0

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?

M. Barbieri
  • 512
  • 2
  • 13
  • 27

1 Answers1

2

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
M. Barbieri
  • 512
  • 2
  • 13
  • 27
Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
  • 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. – M. Barbieri May 18 '16 at 15:05
  • @M.Barbieri looks like it's a known bug https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847 try to install `apt-get install python3-pip` – Daniil Ryzhkov May 18 '16 at 15:07
  • I got it to work, just add the command 'virtualenv -p python3 newenvname' where you put python3 -m venv newenv', thanks!!!! – M. Barbieri May 18 '16 at 15:31
  • I did it already, no worries! – M. Barbieri May 18 '16 at 15:32
  • You can run `virtualenv -p python3 currentenv` if you want to keep using the same name for your virtualenv – goonerify Jun 19 '18 at 11:40