I'm working on WSL2 Ubuntu. I've been taking a course in backend API development using Fastapi. My Ubuntu default python is 3.8 I believe. I'm trying to use python 3.10.0 for my development. I've done the following:
My problem is that when I look into the .venv/bin file, all of the symbolic links show python 3.8.
drwxr-xr-x 2 mryan mryan 4096 Feb 1 23:12 .
drwxr-xr-x 4 mryan mryan 4096 Feb 1 23:12 ..
-rw-r--r-- 1 mryan mryan 2152 Feb 1 23:12 activate
-rw-r--r-- 1 mryan mryan 1444 Feb 1 23:12 activate.csh
-rw-r--r-- 1 mryan mryan 3033 Feb 1 23:12 activate.fish
-rw-r--r-- 1 mryan mryan 1303 Feb 1 23:12 activate.nu
-rw-r--r-- 1 mryan mryan 1754 Feb 1 23:12 activate.ps1
-rw-r--r-- 1 mryan mryan 1199 Feb 1 23:12 activate_this.py
-rw-r--r-- 1 mryan mryan 333 Feb 1 23:12 deactivate.nu
-rwxr-xr-x 1 mryan mryan 249 Feb 1 23:12 pip
-rwxr-xr-x 1 mryan mryan 249 Feb 1 23:12 pip-3.8
-rwxr-xr-x 1 mryan mryan 249 Feb 1 23:12 pip3
-rwxr-xr-x 1 mryan mryan 249 Feb 1 23:12 pip3.8
lrwxrwxrwx 1 mryan mryan 18 Feb 1 23:12 python -> /usr/bin/python3.8
lrwxrwxrwx 1 mryan mryan 6 Feb 1 23:12 python3 -> python
lrwxrwxrwx 1 mryan mryan 6 Feb 1 23:12 python3.8 -> python
-rwxr-xr-x 1 mryan mryan 236 Feb 1 23:12 wheel
-rwxr-xr-x 1 mryan mryan 236 Feb 1 23:12 wheel-3.8
-rwxr-xr-x 1 mryan mryan 236 Feb 1 23:12 wheel3
-rwxr-xr-x 1 mryan mryan 236 Feb 1 23:12 wheel3.8
When I try using the command poetry env use 3.10.0 I get the following:
(.venv) mryan ~/python/fastapi1/.venv/bin $poetry env use 3.10.0
/bin/sh: 1: python3.10: not found
EnvCommandError
Command python3.10 -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 127, and output:
at ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/utils/env.py:378 in activate
374│ shell=True,
375│ )
376│ )
377│ except CalledProcessError as e:
→ 378│ raise EnvCommandError(e)
379│
380│ python_version = Version.parse(python_version.strip())
381│ minor = "{}.{}".format(python_version.major, python_version.minor)
382│ patch = python_version.text
(.venv) mryan ~/python/fastapi1/.venv/bin $python3.10
python3.10: command not found
What am I doing wrong here? I feel I'm missing something significant here. I've been through a zillion web pages on poetry and virtual environments.
I had the same problem you are having, I used to be able to use:
pyenv local 3.10.0
poetry new example-project
And poetry would create example-project with a venv in it based on python 3.10.0. This no longer worked for me so I found that these commands did work for me:
poetry new example-project
cd example-project/
poetry env use 3.10.0
poetry update
In case your project already had a venv installed it might be a good idea to remove that first before using the poetry env command. I'm pretty sure you haven't added pyenv to your PATH properly. Check out the installation instructions for pyenv, specifically the 'Configure your shell's environment for Pyenv' section.
I am surprised that poetry shell creates .venv. Are you certain about that? Or did you maybe create it with virtualenv?
I just kind of replicated what you probably did and did not get the error. I would recommend you to create a minimal, reproducible example. Then you will probably catch what is wrong. For this I case I recommend creating a bash script. A start could be:
mkdir ~/python/test_error
cd ~/python/test_error
cp ~/python/fastapi1/pyproject.toml .
pyenv local 3.10.0
poetry env use 3.10.0
This script works for me (when I change the folders).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With