I have a project that I want to work in a different Python version from my OS. In this example my OS is Ubuntu 22 - Python 3.10.4 and I want to create a project using Python 3.8.4.
When we want to work with a new python environment with different libraries from our OS system we usually create new environment through virtualenv
for example. Whit this approach we will have the env
folder inside our main project and we can commit it to our github repository. Once one clone it, just activate the environment and (env)$ pip3 install -r ./requirements.txt
in order to load all python dependencies for that project.
The problem using virtualenv
is that it creates a copy
from my OS python version when building a virtual environment. The point here is that, as said before, I have python 3.10.4 and I need 3.8.4 in my env
.
In order to achieve this I installed the pyenv. It works like a NVM to nodejs and I can easily switch between python versions in my OS without mess or affect my main OS.
Following the instructions in the documentation I managed to install the version 3.8.4 in my system. In fact it installs the desired versions inside ~/.pyenv/versions
and then from there we can switch versions.
$ pyenv versions
system
3.8.4
3.8.4/envs/test3.8
* test3.8 (set by /home/user/Documents/vhosts/py-whatsapp-message-response-automation/.python-version)
In order to create a virtual environment env
folder inside my repository would be enough to switch the python version in my operational system through pyenv
approach and then follow the instructions to create the virtual environment using python3 -m venv env
. I did not test this option.
Instead, I followed the steps Using pyenv to Install Python in the documentation. It works and creates kind of link between my Project Repository and the Python version inside ~/.pyenv/versions
. From here I can activate the environment and install the desired libraries.
The main problem here is that, if another user clones the repository it will not have the env
folder in order to install the libraries to the project through (env)$ pip3 install -r ./requirements.txt
. All the information about this repository are located out of the repository at ~/.pyenv/versions
and it can't be commited.
I would like to know how to create the env
folder or environment
folder inside the project using pyenv
approach in a way that I could make it available to be commited in the version control.