How can I install a local version of my package with poetry? non setup.py file #1135
-
I know that poetry is supposed to replace I would ideally want to install my package system-wide, or a virtualenv of my choice, so I can run it no after going into Edit: one thing I noticed, is that my package is (re?) installed every time I run poetry install.. |
Beta Was this translation helpful? Give feedback.
Replies: 39 comments 33 replies
-
I figured out the problem. Because |
Beta Was this translation helpful? Give feedback.
-
Can you clarify what you're trying to do? Either of the following should work:
|
Beta Was this translation helpful? Give feedback.
-
I'm talking about being able to import my package inside a file outside of my package directory. # ~/Desktop/test_file.py
from mypackage.decorators import deco In Terminal: $ cd Desktop
$ ./test_file.py This throws an With |
Beta Was this translation helpful? Give feedback.
-
The problem is: when you do |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
To answer the original question: If I understand correctly, poetry is a development tool. It works in a virtualenv (one it creates or one that is managed externally, depending on your options) and provides commands (including install) to work on a project in an isolated fashion, because that’s what we want when developping. To have a project globally installable, we shouldn’t reach for a dev tool but for an installation tool: pip! Thanks to PEP 517 integration, you can use Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Problem is,
So, if a given library uses Poetry, how can I clone its github repo and install it locally to use in my projects? (in editable mode, so I can also make changes to the library itself)? |
Beta Was this translation helpful? Give feedback.
-
I think what may help you is the poetry build command. This will create a wheel and a tar file and place it in the |
Beta Was this translation helpful? Give feedback.
-
Did this behavior change? I just tried and the package was installed locally with |
Beta Was this translation helpful? Give feedback.
-
The issue is not about a local development of a package, but about installing the package in the editable mode in another project, which normally would be handled via |
Beta Was this translation helpful? Give feedback.
-
@jaklan I see, thanks for the explanation. So I am guessing that using my_package = { path = "my/package/path" } Would not install it in editable mode? BTW: is editable mode just putting a symlink in |
Beta Was this translation helpful? Give feedback.
-
@cgarciae Yeah, that would work:
But... only when you also use poetry for that second project ;) Which is not always possible, especially with some legacy projects or e.g. Data Science projects, which are often based on conda envs and files (which is not a problem normally, because in environment.yml I can just use Ad. BTW - here's a detailed explanation: |
Beta Was this translation helpful? Give feedback.
-
Editable mode can be a symlink in site-packages (flit does that), or a |
Beta Was this translation helpful? Give feedback.
-
Maybe this issue should be renamed to something like 'Poetry should support installing local packages in editable mode'? What works for me is indeed just symlinking the local library folder to # I'm assuming your package is called 'my-lib' and your folder where
# you want to test is called 'my-code'
# Create venv first
cd ~/my-code
virtualenv env
source env/bin/activate
# Now install the local library
pip install ~/my-lib
# And delete the directory, assuming you're using python 3.6
rm lib/python3.6/site-packages/my-lib
# Now add a symlink
ln -s ~/my-lib ~/lib/python3.6/site-packages/my-lib |
Beta Was this translation helpful? Give feedback.
-
@jaklan The data science worflow is exactly how I found this issue. Building a toolkit that will likely serve as a jupyter-centric assist within conda env. rather than require jupyter as a hard dependency, my plan was to have a notebooks top-level folder with an This conda env would depend on a pypi-hosted version of my package eventually, but in development I'm used to satisfying that dependency via a local development installation ( Loving poetry so far but this is a bit of a roadblock to clean conda-centric dev. |
Beta Was this translation helpful? Give feedback.
-
I struggled with this, and then learned that you can poetry add with a
relative path. So inside of poetry project A, you can do
$ poetry add ../other_project_b
And then it will be available in your project A.
…On Mon, Jun 22, 2020 at 1:57 PM Neil ***@***.***> wrote:
@finswimmer <https://github.com/finswimmer> What do you propose users of
poetry do to achieve editable installs?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/python-poetry/poetry/issues/1135#issuecomment-647739207>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAI53QVDBPAJPR7OHWM6L3RX6ZTHANCNFSM4HQQRHQQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for repeating exactly the same what @finswimmer wrote 2 comments above and not understanding the question at all - we're talking here about:
@NeilGirdhar it seems @rmvanwyk workaround with |
Beta Was this translation helpful? Give feedback.
-
@jaklan Right, I'm asking about editable mode. Generating setup.py is unfortunate since the whole point is to just rely on modern pyproject.toml. finswimmer might be right that this is pip's problem, but it doesn't seem that pip is going to fix this. Therefore, I would prefer if poetry simply added a
I'm sure it could be better. |
Beta Was this translation helpful? Give feedback.
-
@NeilGirdhar I fully agree. The topic on There was also some discussion here, but it's also dead for months... I really don't understand the |
Beta Was this translation helpful? Give feedback.
-
Hi, just stumbled over this ticket. I had about the same problem, I wasn't able to install a package in editable mode within an environment created with poetry. Anyway, whenever I ran My installed modules in the Poetry virtual environment:
setuptools is there, but why the heck it's not usable by setup.py? Any ideas? I solved it by removing pyproject.toml, delete poetry.lock and created a normal virtual environment using Regards, Thomas |
Beta Was this translation helpful? Give feedback.
-
Update for people struggling with this. Editable installs seem to work for me now provided you do the following:
[build-system]
requires = ["setuptools", "poetry_core>=1.0"]
build-backend = "poetry.core.masonry.api" (This should fix @mosesontheweb's error)
poetry build --format sdist
tar -xvf dist/*-`poetry version -s`.tar.gz -O '*/setup.py' > setup.py
However, installing a project in editable mode doesn't help you make it available to another poetry virtual environment. I don't think the proposed solution above of adding a relative path dependency is good because you might end up committing that dependency, which is probably not what you want. Edit: If it is what you want, poetry recently added an editable install command for that purpose. The best approach I've found is to enter a poetry shell and from there Given that we have a workaround, I've come to accept that @finswimmer is correct that this needs to be solved at pip's end. The corresponding issue is pypa/pip#6950. They decided that they shouldn't decide and deferred to the Python people here: https://discuss.python.org/t/specification-of-editable-installation/1564/40 and pypa/packaging-problems#256 (comment). That discussion seems to be frozen. Edit: PEP 660 addresses this issue. |
Beta Was this translation helpful? Give feedback.
-
@finswimmer 's answer makes me wonder why there is no way to pin an answer. In threads like this one that would really be helpful. |
Beta Was this translation helpful? Give feedback.
-
@cglacet GitHub has a (beta) feature called discussion. I wonder if poetry is eligible. That would maybe a better fit for such questions that are not bugs. |
Beta Was this translation helpful? Give feedback.
-
We have it enabled if you want to check it out — it's pretty good! |
Beta Was this translation helpful? Give feedback.
-
https://github.com/python-poetry/poetry/discussions I don't know if we are idiots, or blind, or if someone just played a trick on us... :D |
Beta Was this translation helpful? Give feedback.
-
To add to the discussion: To get around that limitation, poetry document here already provided the answer to set
Now poetry will generate a link to the directory, so you can directly make changes in that repo. Hope this can help someone facing the same challenge as me. |
Beta Was this translation helpful? Give feedback.
-
I wanted to install the existing package with the existing If you already have in
Then, just run Only that worked for me |
Beta Was this translation helpful? Give feedback.
-
Recipe for vscode
poetry add zzgui
zzgui -> zzgui-
"env": {
"PYTHONPATH": "../zzgui:../zzdb"
}
"python.autoComplete.extraPaths": ["../zzgui", "../zzdb"] It is not very clean, but at least i can do what i want :) |
Beta Was this translation helpful? Give feedback.
-
Is seems that it is enough to add
Then import my_package works and the library is editable. Documentation: https://python-poetry.org/docs/pyproject/#packages Nothing like this is not needed:
|
Beta Was this translation helpful? Give feedback.
-
why not run the following as a solution?:
|
Beta Was this translation helpful? Give feedback.
Lot's of confusion here. I try to summarize it:
poetry install
by default.poetry add ../relative_path/to/package_folder
pyproject.toml
instead ofsetup.py
- in development mode bypip
, is currently not possible. But that's onpip
's side and not onpoetry
's. See also: pypa/pip#6434Edit (2021-07-15): Since poetry 1.1
poetry add ../relative_path/to/package_folder
doesn't add the path dependency in editable mode by default (see docs). For now you have …