pyenv-virtualenv
pyenv-virtualenv copied to clipboard
python3 does not see a pip-installed package, but python does, despite both being python3.9
Minimal reproduction steps
- Create a new project (e.g.
mkdir -p ~/projects/test-project
) - Create its own virtual environment:
$ cd ~/projects/test-project/
$ pyenv install 3.9.0
$ pyenv virtualenv 3.9.0 testproject-venv
$ pyenv local testproject-venv
- Create a simple script which requires a missing package:
$ printf "from money import Money\nprint(\"Success\")" > main.py
- Attempting to execute the script fails as expected:
$ python3 main.py
Traceback (most recent call last):
File "/home/ng/projects/test-project/main.py", line 1, in <module>
from money import Money
ModuleNotFoundError: No module named 'money'
- Install the missing package:
$ pip install money
- Re-attempt to launch the script and see it fail when using
python3
but succeeding withpython
:
$ python main.py
Success
$ python3 main.py
Traceback (most recent call last):
File "/home/ng/projects/test-project/main.py", line 1, in <module>
from money import Money
ModuleNotFoundError: No module named 'money'
Both python
and python3
are aliases to the same binary:
$ ls -lh $(pyenv which python)
lrwxrwxrwx 1 ng ng 9 Dec 6 15:04 /home/ng/.pyenv/versions/testproject-venv/bin/python -> python3.9
$ ls -lh $(pyenv which python3)
lrwxrwxrwx 1 ng ng 9 Dec 6 15:04 /home/ng/.pyenv/versions/testproject-venv/bin/python3 -> python3.9
What am I missing? Thanks in advance :)
What you miss is that pyenv which python doesn't guarantee you, that you execute python3 from this path.
What is the output of command -V python3
?