0

I've been using virtual environment successfully for some time, but this is the first time i run into such a problem.

In my virtual environment i have Python 3.5 + Django package + number of other packages. I successfully run my Django app using Python 3.5 from virtual environment on machine A.

On machine B, after I source env/bin/activate my virtual environment. python command would start Python 2.7 + no Django package present.

How do i investigate this and make venv behave in same way on both machines?

Denys
  • 4,287
  • 8
  • 50
  • 80
  • How did you migrate your virtual env? – Matthias Gilch Jan 23 '17 at 16:22
  • Do you have something in the .bashrc, for example, that puts Python 2.7 on the path? – Metropolis Jan 23 '17 at 16:23
  • Possible duplicate of [Installing python3 in a python2 virtual environment](http://stackoverflow.com/questions/41390053/installing-python3-in-a-python2-virtual-environment) – e4c5 Jan 23 '17 at 16:25
  • Just creating an a virtualenv does not give you the exact same result. Plesae refer to the dup target. The only difference between that dup target and this is that you have to copy requirements.txt to another computer instead of another directory – e4c5 Jan 23 '17 at 16:26
  • @MatthiasGilch git – Denys Jan 23 '17 at 17:01
  • why don't you use virtualenwrapper?It makes easy to organize envs and be sure you've created python3 virtualenv,default is 2.7 –  Jan 23 '17 at 17:28

1 Answers1

0

There are two options to get the same Python version in a virtual environment.

  1. Check if there's Python 3.5 installed on your machine by typing

    python3 -V
    

    into the command line. If it says 3.5.x you can go on and create a virtual environment with

    pyvenv /path/to/your/new/venv
    

    You may install your packages (Django, etc.):

    on machine A

    pip freeze > requirements.txt
    

    transfer requirements.txt to machine B and do

    source /path/to/your/new/venv/bin/activate
    pip install -r requirements.txt
    
  2. If the python version that you've checked in 1. is not 3.5.x you have to compile this version by yourself. Check this question Use different Python version with virtualenv

Community
  • 1
  • 1
  • Thanks Matthias! Now I am getting really confused. I always thought that virtual environment physically stores all the Python versions and packages you install into it, so that when you move your virtual environment to another machine - all those Pythons and packages are waiting there for you in the venv folder. Is that not the case? – Denys Jan 25 '17 at 08:31
  • I don't know all the details. But it is recommended to build your virtual environment with the same python version and then reinstall the new packages via a requirements file. – Matthias Gilch Jan 25 '17 at 09:36