Reputation: 13
I'am new to Poetry and I have an issue that I couldn't find much info about online. My poetry is supposed to create a virtual env of python 3.9, and it did. Here's what I got with the commande poetry env info
:
Virtualenv
Python: 3.9.10
Implementation: CPython
Path: /home/..../.venv
Valid: True
System
Platform: linux
OS: posix
Python: /usr
And when I type poetry shell
then python
, I did get into a python 3.9 and I was able to import the packages that installed. But here's the weird part. When I tried to checked one of the packages that installed, here's what I got:
>>> import XXX.python_utils as utils
>>> utils
<module 'XXX.python_utils' from '/home/X/.local/lib/python3.9/site-packages/XXX/python_utils/__init__.py'>
I do have a actual python 3.9 installed in my machine, but Poetry is supposed to install the package in the virtualenv instead of the actual python3.9 site_packages right? I then tried my python 3.9 installed in my machine instead of virtual env, the packages can still be imported. The outcome is the same as above.
Then I double checked what's in the .venv/lib/python3.9/site-packages
, there's basically nothing inside. What I did found is some repositories with the name of the package and ends with .dist-info
. I'm not sure what's that about.
I also tried which python
in the poetry shell
, and here's what I got:
(.venv) XXX@XXX:~/XXX$ which python
/home/.../.venv/bin/python
It seems like poetry does use the python 3.9 in the venv
And finally, everytime I ran a poetry install
, it install all the packages even I didn't change anything in my pyproject.yaml
It seems like the poetry.lock
means nothing.
Upvotes: 1
Views: 25004
Reputation: 6602
you could try:
poetry env remove python
poetry config virtualenvs.in-project true
and then execute following commands in your project folder:
poetry shell
poetry add your_lib
poetry install
the poetry env remove python will clean your global python env, and the poetry config virtualenvs.in-project true will tell poetry only create .venv in your project folder.
Upvotes: 11
Reputation: 168957
/home/X/.local/lib/python3.9/site-packages
That's not "actual python3.9 site-packages" (i.e. system python3.9 site-packages), that's your PEP 370 per-user site-packages directory. Is it possible you've installed the packages (or some of them) without Poetry or a vanilla virtual environment enabled? It could well be possible that Poetry decides not to install dependencies in the project venv that are ambiently available in your local site-packages already.
You can use pip list --user
without a virtualenv activated to see what packages have been installed in that local directory, and use e.g. pip uninstall
to uninstall them.
You could also see what happens if you move that directory out of the way (e.g. rename python3.9
to python3.9-temporarily-out-of-the-way
) and ask Poetry to install packages.
Upvotes: 0