I successfully installed a virtual environment in Ubuntu 22.10 (VirtualBox) by following this excellent tutorial: www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-ubuntu-22-04. Thank you, Alex. I have two follow up questions:
my_env
directory that is created by the python3 -m venv my_env
command. Is this correct? I am asking, because I am planning to create a second virtual environment, and to use a different/older version of Ptyhon. Somehow I feel I should be working from within the respective directory created by the venv
command, especially since I will have more than one environment.Thanks. I have always found the DigitalOcean tutorials comprehensive and well-written.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi there,
You will be working form the directory that you’ve created with the mkdir
command.
For example let’s say that you have 2 projects:
project1
then cd
into it and create the venv, python3 -m venv p1_env
project2
then cd
into it and create the venv, python3 -m venv p2_env
For your second question, in order to install Python 3.9
on Ubuntu, you can use the pyenv
CLI to install specific Python versions:
https://github.com/pyenv/pyenv#getting-pyenv
sudo apt-get update sudo apt-get install git curl python3-pip gcc make zlib1g-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev
curl https://pyenv.run | bash
This will download and run the pyenv installer script. It will add the necessary configuration to your shell profile file (e.g. ~/.bashrc) to initialize pyenv on each new terminal session.
source ~/.bashrc
pyenv --version
This should output the version of pyenv that you installed.
pyenv install 3.10.0
This will download and install Python 3.10.0. You can install other Python versions in the same way.
pyenv global 3.10.0
This will set the global Python version to 3.10.0. You can also set the Python version for a specific directory using the pyenv local
command.
Let me know if you have any questions!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.