What is the process for setting up a project and using an earlier version of Python which has not been installed as a system-wide binary?
Ideally, poetry add <package>
should install to that previous version of python, and poetry shell
should open up a virtual environment with the correct version.
I have tried:
mkdir myproj
cd myproj
eval "$(pyenv init -)"
pyenv install 3.8.9
pyenv local 3.8.9
poetry init --no-interaction --python="3.8.9"
poetry env use 3.8.9
poetry add numpy
echo '
import sys
print(sys.version)
import numpy
print(numpy.__version__)
' > main.py
poetry shell
eval "$(pyenv init -)"
python main.py
But this gives:
3.8.9 (default, May 1 2021, 22:43:00)
[GCC 10.2.0]
Traceback (most recent call last):
File "main.py", line 5, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
...indicating that the correct version of python
ran (as expected), but that the package was not installed to python 3.8.9. Indeed:
λ ls "$(poetry env info --path)/lib"
python3.9
λ grep "version_info" "$(poetry env info --path)/pyvenv.cfg"
version_info = 3.9.4.final.0
pyenv
, you clearly know a possible answer - what have you tried and what is the problem exactly? – Inscriptionnumpy
into the environment, but when running a script, it appears not to be available) - I had a quick look, but see no clear mistake or solution, upvoting your question. – Inscription