McMitch
McMitch

Reputation: 31

Trouble changing the Python Interpreter in Windows

So I have some code, it runs fine in my IDE (PyCharm) as it is using the correct interpreter (Anaconda2).

I can run the program from CMD by typing python myProgram.py and this uses the correct interpreter, but I need the program to run on double click, yet when I do this it gives an error and immediately shuts down.

The error when running

This is almost definitely down to it using the wrong interpreter, even when I right click and select 'Open With' and select the same python.exe that my IDE is using it gives the same error.

My windows Environmental Variables include Anaconda as the path, as shown here

I have tried:

How can I make sure my program is always run using a specific interpreter? Specifically when double clicking to run it?

Thanks

Upvotes: 2

Views: 72

Answers (2)

Pax Vobiscum
Pax Vobiscum

Reputation: 2639

If your python interpreter is named the same in your anaconda installation as your original python2.7 installation, you are going to have problems. Try renaming one of them. Like calling python in your python2.7 installation python2.

Edit In order for the response not to be to long of a comment, I make this an edit.

If you run it from cmd you can specify interpreter.

<interpreter-name> yourfile.py

However when setting default program to run your python files, it will be the same from everyone. Thus you need to specify with cmd if you want to run it with a different interpreter.

Upvotes: 1

Jake Irvine
Jake Irvine

Reputation: 53

The reason the #!/usr/bin/env python (this is called a shebang) does not work is that that is a feature of the linux shell, bash (a shell is a program that you use to input commands, like cmd.exe on windows)

As for the answer, try looking in the build/run configurations of your IDE and look at what command is being run from there. Also, you should add the anaconda directory to the system path, not the user one, and I think path needs a capital P

Upvotes: 1

Related Questions