Reputation: 946
I have installed Anaconda with Python3
. Then, I additionally created a virtual environment with Python2
. There are no other Pythons on the computer. My problem:
If I run the command
python C:\Path\To\myScript.py arg1 arg2
in CMD, Python 3.4 is used to execute myScript.py
(as expected/desired). But! If I create a .bat
file that contains precisely the upper command, Python 2.7 is used. (I check the version with the command print(sys.version)
in myScript.py
).
How can I fix that?
Upvotes: 0
Views: 105
Reputation: 2912
Try specifying the full path to the Python3 (ie. /path/to/Python3 ) executable in your batch script. It's probably defaulting to the system python.
If you are using a virtualenv, and you probably should be, there is a separate python executable at venv/bin/python (or similar under Windows) - using this specific executable by absolute path is often the easiest way to ensure the correct python environment is being used, especially when scripts are run automatically or by a different user. This is entirely by design, virtualenv is often used this way.
Upvotes: 2
Reputation: 311
You can either change the default version of python by changing the value of path variable this can be done by following this answer How to update PATH variable permanently from cmd? Windows
Or you can temporarily change the version you want to use follow this for that How to run different python versions in cmd
I hope my answer was helpful.
Upvotes: 0
Reputation: 3965
since you're using Anaconda, adding a line source deactivate
before the python command would deactivate any virtualenv explicitly
edit: it's probably just deactivate
for windows cmd prompt
Upvotes: 0