Heschoon
Heschoon

Reputation: 3019

Running python from a conda environment on windows

I have decided to have both python 2 and 3 installed on my Windows PC. Python 3 was included with Anaconda, and works flawlessly after the installation of Anaconda.

After having created successfully a python 2 environment:

conda create --name py27 python=2.7

I noticed that no python.py file has been created in C:\Users\Hélain\IT\Anaconda3\envs\py27.

Typing python in my terminal launches my python 3 python and py27 is not considered a command. Activating or deactivating the environment does no change this behavior.

Result of typing python:

C:\Users\Hélain>activate py27
Deactivating environment "C:\Users\Hélain\IT\Anaconda3"...
Activating environment "C:\Users\Hélain\IT\Anaconda3\envs\py27"...

[py27] C:\Users\Hélain>python
Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1
600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

How do I run python with my environment's version and packages?

Upvotes: 7

Views: 33289

Answers (3)

information_interchange
information_interchange

Reputation: 3118

I think you mean python.exe in your environment? From my understanding, all your Pycharm projects can point to the same Anaconda interpreter (stored outside the environment folders) and then to propagate an envrionment change to Pycharm, you just need to do it from the Conda prompt

Upvotes: 0

fanbyprinciple
fanbyprinciple

Reputation: 780

Below are the steps to run python code written in python 2.7 syntax.

In order to run any python file (for example, as you mention python.py) after successfully creating a conda environment is-

  1. Activate the environment - activate py27
    This works on windows. In linux/mac type source activate py27 Prompt should change to (py27).
  2. Navigate to the directory where you created your python.py file.
    If you have not created any .py file, simply open a notepad and rename it as python.py. Write your code. Right now for testing purpose, simply write print "Hello".
  3. Now in the terminal just enter python.py or the name of python file. It should run and print Hello.

I am not that experienced to know much about the python version conflict you encountered while running the python command. But you should check the github repo for issues related to conda for more information on this. It may be a bug.

Upvotes: 0

Mike Müller
Mike Müller

Reputation: 85422

In your terminal type:

activate py27

The prompt should change to (py27).

Now you can install packages in this environment. For example:

conda install jupyter matplotlib

Launch Python from this terminal with:

python 

Upvotes: 1

Related Questions