I am having trouble because I have an existing django project app which I am currently working under a virtual environment. However, the python version for that environment is 2.7. I need to somehow switch that to python3.4 if at all possible. I realize there's the possibility of just creating a new environment, but I don't know how to create a new one with existing django files and a new python version. Anyone know what I should/could do?
1 Answer
Activate your old Python 2.7 enviroment:
source /path/to/your/env/bin/activate
Save dependencies:
pip freeze > env.txt
Create new Python 3.x enviroment:
virtualenv -p python3 newenvname
Activate new environment and install all dependencies from the old environment from env.txt
:
source newenv/bin/activate
pip install -r env.txt
-
Thanks for the speedy response! This seems to be a great answer to my problem, I am just running into the problem where I am trying to run the command 'python3 -m venv newenv' and ubuntu tells me that 'The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubunmtu systems, you need to install the python3-venv package', and I try doing a 'sudo apt-get install python3-venv' however it doesn't locate that package. May 18, 2016 at 15:05
-
@M.Barbieri looks like it's a known bug bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847 try to install
apt-get install python3-pip
May 18, 2016 at 15:07 -
I got it to work, just add the command 'virtualenv -p python3 newenvname' where you put python3 -m venv newenv', thanks!!!! May 18, 2016 at 15:31
-
-
You can run
virtualenv -p python3 currentenv
if you want to keep using the same name for your virtualenv Jun 19, 2018 at 11:40