Can I temporarily set python to default to an earlier version? - python

Can I temporarily set python to default to an earlier version?
I have been trying to run a few scripts I downloaded from GitHub written in python 2.7 and my default python version is 3.7.6. I know that I can run one script with 2.7 using: python2 FoEC.py -i ./testdata/ for instance. However, this script calls other .py scripts also written in 2.7 that I believe are running using 3.7.6 (the keep getting syntax errors which don't appear when run in 2.7). Is there a way to ensure that all scripts are run using python 2.7?
I hope that this makes sense.
Thanks,

Related

Terminal's python version and Eclipse's python version mismatch

My MacBook came preinstalled with Python 2.7.16, and I downloaded Python 3.8.5. To my understanding, the operating system needs Python 2.x so I did not uninstall it.
Eclipse (using Pydev) is the IDE I'm using.
I set up two interpreters, one for python and the other python3.
I set up one project for each interpreter to make sure I set them up correctly.
The script is:
import sys
print(sys.version)
When I run it with the python interpreter, I correctly get version 2.7.16.
When I run it with the python3 interpreter, I instead get 3.8.2.
Running python -V yields ``Python 2.7.16. Running python3 -VyieldsPython 3.8.5```.
Why does the interpreter return one version and the terminal another?
I'm at a loss for how to troubleshoot or fix this, or if it is a non-issue.
To clarify, you get the 2.7.16 and 3.8.2 versions when running your program from within Eclipse. The python -V is clearly from the command line. The interpretation is that your Eclipse environment came with its own python interpreter which happened to be 3.8.2. Have you tried running your script from the command line with python3 path/to/your/script.py? This probably gives 3.8.5. I don't see a real problem here in most cases you do not care whether you have python 3.8.2 or 3.8.5.
The "biggest" issue is a cosmetic one that you have two python3 installations which is a bit of a waste. When using additional libraries, you may find that you have to install them in your Eclipse environment and in your command line if you want to use your scripts in both environments which would be a bit tedious. If this does turn out to be a problem, check in Eclipse whether there is any way to change your python3 configuration to use the interpreter used by the command line (sorry cannot be more specific, it's a long time that I used Eclipse).

Git-bash using wrong version of Python

I am new to git-bash and am currently trying to make the Git Bash use the correct version of Python. I just installed version 3.8.1, but Git is using the 3.7.3 version.
When I run the which python command, it displays the directory of the 3.7.3 Python as expected. How can I switch it so that it is using the updated version?
Let's say, for example, the location of the Python I want to use is /c/Users/tom/Python3.8.1/python.
I am tried to solve this by searching online and I came across a post that suggested I use the following command:
PATH="path to executable python":PATH
But that did not seem to work as after I ran that, it would no longer let me use the which python command

environment with multiple python interpreter

On Mac, if installed multiple Python interpreter (anaconda, Python 2.7 standard, etc.), wondering when running command python, is there a way to specify if I run with anaconda or Python 2.7 or other Python interpreter?
If you only type python, it will take you to the version of python specified by this:
which python
This command will print out the location of python in your terminal.
To use a version other than the one above, be it Jython or Anaconda or whatever, you can to run it by typing out the fully qualified path.

Python code in OSX Terminal not compiling right

So I am trying to teach myself to program in Python while on spring break and I have run into a roadblock. I can get my code to compile in PyCharm, but I would really like to get it to compile correctly in Terminal because vim is my text-editor of choice. Does anyone have any idea of why my code may not be compiling correctly?
Here is my code compiling correctly in PyCharm
Here is my code compiling incorrectly in Terminal
Thank you in advance for any help.
Any recent OSX version comes with Python 2.7 as a standard. When you install Python 3.x, you have both versions on your system. The standard way of using python -command- in the terminal calls Python 2.7. You can call a command using python3 -command- instead to use Python 3.x. You could set an alias on python3 in .bash_profile to call it instead when you use python.
You have configured PyCharm to use an installed Python 3, but at the terminal you appear to be using Python 2. There is a difference in how the two versions output the results of print. Try modifying your terminal session to direct your path to use the installed Python 3 instead of the installed Python 2.

how to set python IDLE's default python?

I installed python 3.2 and later installed python 2.7. Somehow the IDLE, which I open it by right-click on python file -> Edit with IDLE, are using python 2.7 instead of python 3.2.
It seems that python 2.7 was set as default with IDLE. Even if I changed the PATH environment variable in windows advance setting back to python 3.2, the default python shell is still 2.7. I am sure that there was no more python 2.7 in the path.
Later I have to uninstall python 2.7 and reinstall python 3.2.
The IDLE context menu plug-in is registered when you install Python and points to the version of IDLE supplied with the Python installed. (IDLE itself has significant code changes between Python 2 and 3 because it's written in Python and the language changed a lot.) To change it, simply re-install the version of Python you wish the IDLE context menu to invoke.

Categories

Resources