-1

I am trying to have two environments in anaconda, one with python 3.4 and one with python 2.7. I already had everything working for python 3.4 and created a new environment with:

conda create -n python2 python=2.7 anaconda

and i activated this with:

activate python2

When i then run python, it still uses packages from C:\anaconda3\lib. Here are the standard packages for python 3.4 located (I think). This will give errors when using python 2.7. How can i make sure the python 2.7 environment uses al standard packages for python 2.7?

I tried manually copying the files to C:\Anaconda3\envs\python2\lib, but without success.

user4493177
  • 750
  • 11
  • 32
  • 1
    Which packages are you needing/using that are giving errors? – Matt P Jun 03 '17 at 20:15
  • Not sure if it is a package or a part of a package, but re.py for regular expressions. – user4493177 Jun 03 '17 at 20:16
  • version 2.2.1 [Comment character length is too low] – user4493177 Jun 03 '17 at 20:21
  • 1
    That's part of the standard library. What error are you getting when you try to import/use `re`? – Matt P Jun 03 '17 at 20:29
  • I checked a bit further, but it seems that the problem is not just the RE package, but that python is still running in version 3.5. No idea why – user4493177 Jun 03 '17 at 20:38
  • 1
    Please answer the questions: 1) After you activate the environment `activate python2` and start the interpreter by typing `python`, what version is shown? 2) If the correct version (Python 2.7.x) is printed, what error do you get when you try to use `re` because it's not clear what the problem is. – Matt P Jun 03 '17 at 20:44
  • I found the solution, see below. Thank you for your time and help – user4493177 Jun 04 '17 at 09:45

2 Answers2

0

From: Using Python in Windows

If you have multiple versions of Python installed (e.g., 2.7 and 3.6) you will have noticed that Python 3.6 was started - to launch Python 2.7, try the command: py -2.7

And:

If the launcher is run with no explicit Python version specification, and a virtual environment (created with the standard library venv module or the external virtualenv tool) active, the launcher will run the virtual environment’s interpreter rather than the global one. To run the global interpreter, either deactivate the virtual environment, or explicitly specify the global Python version.

So, I think solution for you is create isolated environment using virtualenv with specific python version:

  1. Install pip instructions are detailed here
  2. pip install virtualenv
  3. virtualenv venv
    • (venv is virtual environment name)
  4. \path\to\env\Scripts\activate

Validate your python version by python -V
If version is 3.4, start your anaconda.

Ardi Nusawan
  • 427
  • 6
  • 12
0

I found why it was not working. I was using Spyder, which sets the environment variable PYTHONPATH to C:\anaconda3\lib.

I removed the variable with

set PYTHONPATH=

in cmd and now it works. The only thing left is that i have to do this every time and i suspect this to be because Spyder changes it back.

user4493177
  • 750
  • 11
  • 32