0

I am looking to set up Python's virtualenv. I am doing this since I need to run some python files written with:

a. Python 2.7 and also need to run some files that were written for python 3.4

b. two different versions of:

  • NumPy - NumPy 1.9.3 and NumPy 1.10.0
  • Matplotlib - Matplotlib 1.5.0 and Matplotlib 1.41

I need to run all these files on the same Windows system (Windows 7 64-bit).

Currently:

I currently have Python 2.7 installed with NumPy 1.9.3 and Matplotlib 1.5.0. I have set up and used virtualenv using the following procedure:

cd C:\Users\WrAU\Downloads
virtualenv venv_test
cd venv_test
venv_test\Scripts\activate
pip install Django==1.0
deactivate

I have added C:\Python27 and C:\Python27\Scripts to my path. I have not yet installed Python 3.4.

My problem:

I need:

  • 2 different versions of Python

  • 2 versions of NumPy and Matplotlib

Questions:

Do I need to create a separate virtualenv for Python 3.4 using the same procedure as I did for Python 2.7 above? Or is there a different method that is required for that?

How do I install separate versions of Python packages to a virtualenv?

5
  • 1
    You might consider tox Commented Jan 5, 2016 at 15:59
  • Thanks. I can see that it is cross-Python compatible. But does it offer the potential for different package versions? Commented Jan 5, 2016 at 16:02
  • Tox creates a virtualenv for each version of python that you specify, and then will install dependencies in that version and run your tests. I'm assuming that you're running tests, though you still could use tox to create the virtualenvs & install dependencies. On Windows though, Numpy and Matplotlib you might have to install in your main Windows install and then use the --system-site-packages when creating your virtualenv. Commented Jan 5, 2016 at 16:10
  • Wayne: Would you be able to post an Answer here with how this could be done with tox? Maybe a simplified approach for one of the packages - NumPy? Commented Jan 5, 2016 at 21:58
  • Wayne: To answer your earlier question - No, I don't plan to run any tests. I simply need to know that my scripts are compatible with different versions of Python. Or did you meant something specific by I'm assuming that you're running tests? Commented Jan 5, 2016 at 22:13

2 Answers 2

1

Yes you do create 1 virtualenv per interpreter. In it you can install matplotlib and numpy. You can create 2 venv with python 2.7 for testing differents versions of matplotlib and numpy, and make the same scheme with python 3.X

Sign up to request clarification or add additional context in comments.

2 Comments

This is the method that I am leaning towards going with as well. It seems like the simplest to understand. However, I think it is going to be very tedious. Suppose I had Python 2.7 with A) matplotlib 1.4.1 and numpy 1.10.1, B) matplotlib 1.4.1 and numpy 1.9.3, C) matplotlib 1.5.0 and numpy 1.10.1, D) matplotlib 1.5.0 and numpy 1.9.3. Based on this, I would need 4 different virtual environments to account for all package version combinations. Or have I misunderstood something?
Yes 4 different virtualenv
1

Under windows I would definitely do it through anaconda/miniconda. Regardless of which version (py3/py2) you install, it can create venvs for py3/py2. For example:

conda create -n app_py2 numpy==1.9.3 matplotlib==1.5.0 python=2
conda create -n app_py2 numpy==1.10.0 matplotlib==1.4.1 python=3

2 Comments

What is app_py2? Is that a virtual environment? And does this mean that a new virtualenv must be created for each combination of packages?
Yes it's just the name of the virtualenv; you may create as many environments as combinations on the same system

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.