pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

python3 does not see a pip-installed package, but python does, despite both being python3.9

Open nachogoro opened this issue 4 years ago • 1 comments

Minimal reproduction steps

  1. Create a new project (e.g. mkdir -p ~/projects/test-project)
  2. 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
  1. Create a simple script which requires a missing package: $ printf "from money import Money\nprint(\"Success\")" > main.py
  2. 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'
  1. Install the missing package: $ pip install money
  2. Re-attempt to launch the script and see it fail when using python3 but succeeding with python:
$ 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 :)

nachogoro avatar Dec 06 '20 14:12 nachogoro

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 ?

grizmin avatar Apr 02 '23 19:04 grizmin