Score:0

Pyenv python management not properly working?

as flag

I am using Ubuntu 18.04 with python 2.7.17 and python 3.6.9 installed by default

I will be having projects that require newer python versions and I am aware that installing and using system-wide python versions may cause some trouble (already done it, it caused trouble when switching versions using update-alternatives)

So, I am currently trying to use pyenv

It looks like the installation was a success

$ pyenv --version
pyenv 2.3.4

I have then installed python 3.10.7 into pyenv, and it also looks like it is a success

$ pyenv versions
* system (set by /home/myuser/.pyenv/version)
  3.10.7

I have then tried creating a virtualenv using pyenv in a project to test it, and when I browse the generated virtualenv directory, I can see some files like this

$ ls -l
total 40
-rw-r--r-- 1 myuser myuser 2041 oct.   7 16:28 activate
-rw-r--r-- 1 myuser myuser  967 oct.   7 16:28 activate.csh
-rw-r--r-- 1 myuser myuser 2109 oct.   7 16:28 activate.fish
-rw-r--r-- 1 myuser myuser 9033 oct.   7 16:28 Activate.ps1
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip3
-rwxrwxr-x 1 myuser myuser  276 oct.   7 16:28 pip3.10
-rwxrwxr-x 1 myuser myuser  128 oct.   7 16:28 pydoc
lrwxrwxrwx 1 myuser myuser   10 oct.   7 16:28 python -> python3.10
lrwxrwxrwx 1 myuser myuser   10 oct.   7 16:28 python3 -> python3.10
lrwxrwxrwx 1 myuser myuser   52 oct.   7 16:28 python3.10 -> /home/myuser/.pyenv/versions/3.10.7/bin/python3.10

However, with the virtualenv activated (it shows the name of the virtualenv between () before the command prompt), pip does not seem to function as intended. Using pip install -r requirements.txt tries to use the python 2.7.17 pip which fails because of version issues, and using pip3 install -r requirements.txt uses the python 3.6.9 pip, which is not what I am trying to do

Collecting orjson<4.0.0,>=3.2.1; extra == "all" (from fastapi[all]->-r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/92/97/895dfe0c2e7820fd5453d0efab6a9036de7f97b4edfd157a6a414dd3b0ee/orjson-3.6.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-8hgeru6w/orjson/setup.py'

I do not even know if some of those packages have been installed globally somewhere as I cannot see any of them nowhere... This is what I was trying to install

fastapi[all]
python-jose[cryptography]
passlib[bcrypt]

Back to the point: when using pip and python commands, the executables being called are not the right ones

$ which python3
/usr/bin/python3

$ pyenv which python3
/home/myuser/.pyenv/versions/myproject/bin/python3

$ which pip3
/usr/bin/pip3

$ pyenv which pip3
/home/myuser/.pyenv/versions/myproject/bin/pip3

I have verified if my PATH was correct, if my shims were set, they were

$ echo $PATH
/home/myuser/.pyenv/plugins/pyenv-virtualenv/shims:/home/myuser/.pyenv/bin:/home/myuser/.local/bin:/home/myuser/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/maven/bin:/usr/lib/android-sdk/tools:/usr/lib/android-sdk/platform-tools:/usr/lib/android-sdk/emulator:/usr/lib/android-sdk/tools/bin

$ pyenv shims
/home/myuser/.pyenv/shims/2to3
/home/myuser/.pyenv/shims/2to3-3.10
/home/myuser/.pyenv/shims/activate
/home/myuser/.pyenv/shims/activate.csh
/home/myuser/.pyenv/shims/activate.fish
/home/myuser/.pyenv/shims/Activate.ps1
/home/myuser/.pyenv/shims/idle
/home/myuser/.pyenv/shims/idle3
/home/myuser/.pyenv/shims/idle3.10
/home/myuser/.pyenv/shims/pip
/home/myuser/.pyenv/shims/pip3
/home/myuser/.pyenv/shims/pip3.10
/home/myuser/.pyenv/shims/pydoc
/home/myuser/.pyenv/shims/pydoc3
/home/myuser/.pyenv/shims/pydoc3.10
/home/myuser/.pyenv/shims/python
/home/myuser/.pyenv/shims/python3
/home/myuser/.pyenv/shims/python3.10
/home/myuser/.pyenv/shims/python3.10-config
/home/myuser/.pyenv/shims/python3.10-gdb.py
/home/myuser/.pyenv/shims/python3-config
/home/myuser/.pyenv/shims/python-config

What do I need to tinker with to make the python or pip commands use the executables from my pyenv generated virtualenvs?

David avatar
cn flag
Two ways you can address this. Upgrade to a newer Ubuntu which uses a newer version of Python. You never said what version you wanted. Ubuntu 20.04 and 22.04 both use different but newer versions of Python. Or you can have multi versions installed and call the one you need for each project. That is beyond here to give you step by step to do. There are many questions that cover that. Keep in mind 18.04 goes EOL in less then 1 year.
gl_prout avatar
as flag
it is stated in my question that I have installed 3.10.7 in pyenv. Also, this is a company computer so I am not allowed to upgrade the OS drastically
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.