just a quick question. I have Python 2.7 on my mac by default. I have also installed 3.4 and use it more than 2.7, but would like to upgrade to the new 3.5. Should I remove 3.4 and just lay down a new install of 3.5, or is there a way to just update it. All my searches just talk about upgrading from 2.7 to 3x. I am just concerned about messing one of the installs up. Any input would be greatly appreciated.
Cheers.
It is a lot safer to change your environment so that Python 3.5 is given preference over the default Python.
There are many ways to do this; if you do them all, it provides the maximum compatibility.
You can set these in your .bash_profile file, which is a hidden file in your home directory.
You can set the PATH environment variable so that Python 3.5 appears first in the search order; like this PATH='/path/to/your/python3.5/directory':$PATH
You can set a local alias in your shell, so that the python command points to Python 3.5, like this alias python="/path/to/the/file/python3.5"
Once you set the above, make sure you restart the terminal application.
If you download the installer form python.org; it will set these environment variables for you.
Also, if you use a utility like brew it will set the shell up correctly for you.
This will ensure that the shell environment will point to version of Python you want; however this does not affect applications that run on the desktop as most of them don't read the shell environment variables.
So, if you are using and IDE like PyCharm you'll still have to manually set the correct Python version for your projects.
This may seem like a lot of workaround, but on most Linux systems and even on OSX, Python is a core part of the system and it is used by some utilities, therefore it is always dangerous to rip and replace the version of Python that came with the operating system.
Related
I've deinstalled and reinstalled a bunch of Python Versions and edited my system variables in order to clean up the quagmire of pip not being able to install packages to the right locations. Long story short: Sublime now can't find numpy (or any 3rd party module), because it somehow figured that the python 2.3 version that comes with ChemDraw is the one I really want to use, not the 3.9 version I had used previously.
I've tried a bunch of tutorials online (such as resetting everything to factory settings) however nothing seems to unlink the python build system from that python 2.3 version that came with ChemDraw. Even deinstalling everything and installing Sublime 4 keeps that association. Like...how?
So here's my problem: My build system for python is linked to the wrong python version and I don't know how to link it to the python 3.9 that's located in AppData/Programs.
How can I associate the python.exe of python 3.9 in AppData with my python Build System instead of the current python 2.3, which is located ProgramFiles?
Ok, so the problem was that there was a system variable called PYTHONPATH, which I don't remember setting. It seems that Chemdraw, if installed with ChemScript, installs it's own python installation, which is 2.X.
That python install seems to set its own system variable called PYTHONPATH, which Sublime seems to prioritize for it's default python build system.
Delete whatever incorrect path is set in PYTHONPATH and paste the following into it instead:
C:...\Python\Python39\Scripts;C:...\Python\Python39;C:...\Python\Launcher;
What is the difference between following commands:
python setup.py
and
python3 setup.py
What if I only have python3.6 installed? python and python3 would do the same thing?
Does it make difference only when I have different versions of python installed? If so, which version will be used with python setup.py?
There is no single correct answer here, but we can offer some common observations.
Some Linux distributions decided during the transition from Python 2 to Python 3 that python should always refer to Python 2, and the command to run Python 3 would be python3 with a 3 at the end. Now that Python 2 is becoming obsolete, this is being relaxed in some distros (i.e. now that they no longer ship Python 2 at all, the python command can be allowed to point to Python 3, too), but this is going to continue to exist in some form for some time.
See PEP 394
Debian-based Linux distros have a mechanism called update-alternatives which lets you define which version of python exactly will be linked to the system-wide standard /usr/bin/python. There is similarly a set of alternatives for /usr/bin/python3.
If you have manually installed Python 3 somewhere, what works depends on where it was installed and whether that location is in your PATH. A common arrangement is to have Python 3.14.159 somewhere like /opt/python-3.14.159/bin/python3.14.159 and then rely on users who want to use this to create a symlink or alias to this binary so that they can simply call it python (or python3, or obviously also e.g. shirley if they prefer that)
If you have an interactive alias, function, or personal shell script in your PATH with either of these names, obviously that overrides any system-wide setting, and could basically do anything at all, including but not limited to running a specific version of Python, ideally with all the command line arguments intact and correctly quoted (/path/to/system-wide/default/python "$#") but obviously with no guarantees of any sort.
On Windows, where many of these facilities don't exist, a common arrangement is for Python to be installed in C:\python3.14.159\bin\Python.exe; you then have to have C:\python3.14.159\bin in your PATH for the python command to work. The installer lets you install the package anywhere, but if you just go with the defaults, this is what you commonly end up with. Because of the cumbersomeness of Windows, the standard install also includes a command py which works around some of the rigidity of the platform to let you flexibly indicate which Python version exactly to run. There is usually not a separate python3 command, though users are of course free to create a CMD file with that name to run Python (or play a video of Rick Astley performing his biggest hit if they so prefer).
To help us help you debug questions about your installation, you will commonly need to tell us exactly what you installed where and how, and show us the value of your PATH. If you have relevant functions, aliases, or personal shell scripts which shadow the system-wide default ones, show them too. On Unix-based platforms, the type and command commands can be used to show what will be executed (many guidances will tell you to use which or whereis, but don't; now we have to guess which non-standard command you are using, and where it is going to look). The Windows command whereis provides roughly the same functionality.
Don't call me Shirley, please.
Yes, it will make difference if you have different versions of python installed.
This depends on the entries in on the PATH environment variable. Suppose you have two python installations, 2.7 and 3.8, now you have installed 2.7 before 3.8, and both were added to PATH, so when you type python, 2.7 interpreter launches. If you have done vice versa, then 3.8 would launch. You can type where python to determine location.
Also one thing is that there is a launcher named py, just type py -3.8 3.8 interpreter will launch and same on py -2.7
I just dealt with the worse bug in my entire 3 years of computer programming! It turns out that because I wanted to work with the natural language toolkit I had to install python 3.5 even though I'm using python 3.6. So I downloaded 3.5 and now my terminal is using python 3.5 by default and I can't get it back to 3.6. Because I was using python 3.5 which does not automatically order dictionaries it was throwing my program off because it relies on ordered dictionaries. It took me 4 hours to figure that out.
You want to use virtualenv and/or virtualenvwrapper. This is a utility that allows you to use multiple different environments, with different Python versions, different pip packages installed, etc.
To find the 3.5 version, run which python in your terminal to find the path to the python executable; then look at your PATH environment, and see where the location of that Python is on your PATH. Then you need to find out where that path is getting added; this will depend on your OS/Shell.
Tough times for sure, sorry to hear that.
I use pyenv to manage the different python versions on my system. This allows you to create virtual environments using whichever version you want.
EDIT to address comments.
I totally understand that setting up virtualenv or something like pyenv is not simple. However, it is unfortunately the easiest way to deal with (and avoid) situations like this. There are two essential concepts that are important here:
1) Isolation - Virtualenv takes care of this. When you install dependencies in a virtual environment, they will not affect your other environments or system python installation.
2) Multiple Python Versions - In your case, you needed to use a module that did not support 3.6. Instead of creating a virtual environment using python 3.5, you accidentally messed up your system installation of 3.6. Recovering from these types of misconfigurations can be difficult, and it is often easier to simply prevent it in the first place.
Again, I completely understand that this might be complicated, I remember thinking the same thing, but it is less complicated than troubleshooting the misconfigurations that can occur without this tooling.
I'm a newbie programmer just installing Python 3.2, but I know I also have an older version of Python on my machine. in fact, I think Macbook comes with it installed. Do I have to worry about having different versions on my computer when I try to start learning Python?
For the most part, you don't have to worry about conflicts with system Python. In fact it is recommended to install a different Python version instead of working with system Python. Also consider using virtualenv and virtualenvwrapper to maintain any dependencies for each project easily without conflicts.
It really depends what OS you're talking about. I'm assuming you're talking about a Mac, since you mentioned Macbook.
Macs come with 2.5 and 2.6 installed as far as I'm aware. At least mine has both those versions, and I've only installed 2.7 manually.
You can check which version of python is the current 'system' python by doing the following in terminal:
// check the version of system python
python --version
// tells you where the system version of python is on your PATH
which python
On *nix type Operating Systems, like your Mac, applications aren't really 'installed', like they are in Windows (eliding details). Instead, application files are placed in various different parts of the file system. Python, for example, is placed into the following directory (by default) when installing 2.7:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Since this directory isn't on the system PATH, this version of python won't be used when simply calling python from the command line. The system will search all the folders in the PATH environment variable for an executable file called python. It will usually find it in /usr/bin/ or something similar.
To make a new version of Python the 'system' python, you have a couple of options:
Modify your .bash_profile, and prepend the path to your new python to the PATH environment variable.
symlink the new version of python to a directory already on your PATH like /usr/bin/
Be aware that Mac python installers can modify your .bash_profile (in your home directory), to force the new version to be the default system version. This is what my bash_profile shows:
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
You can happily run multiple versions of python on the same system. A particular version is usually the default though, and that's whatever executable python file is found on the PATH first.
If you want to use a different version at any particular point in time, you can:
/path/to/python/2.4/python some_script.py
/path/to/python/2.7/python some_script.py
/path/to/python/3.2/python some_script.py
That will execute the script some_script.py under 3 different versions of python. Of course, you need to make sure that the /path/to/python is correct.
So yes, you need to be mindful about what version of python you are going to be using, hopefully this will guide you into understanding how applications are installed and which version of an application is launched by default when you don't provide a path.
Yes, 3.x Python syntax is not backward-compatible with 2.x. So if you learn Python 3.x you might not be able to port your knowledge to Python 2.x.
Moreover you should choose if you want to learn 3.x or 2.x. 2.x is far more widespread than 3.x, but 3.x is where Python is heading. No more innovation will happen in 2.x, and in mid-term most frameworks will be ported to 3.x (right now there are some notable exceptions)
Hope that helps!
In general, you should be fine. Since the Mac is BSD-based, it should maintain the "python" command as pointing to the version that your system requires, which is usually an older version like 2.5. You may have to use a command like python3 to run your Python 3 programs, but other than that it should be transparent to you.
As you learn and become more advanced, you can begin using the virtualenv system to maintain separate Python installations for multiple projects.
Python version with different major or minor version numbers can be installed in parallel. For example, you can have 2.4, 2.5, 2.6, 2.7 and 3.1 on the same machine. However, you can't have versions with the same major and minor number installed at the same time (at least, not without tricks), so you can't have 2.5.2 and 2.5.4 at the same time.
Note that you will have to install any third-party libraries once for every Python version.
It is very well possible to have multiple versions of python on your machine. Just make sure, that if you call python in your console it uses the python you want it to use. Same goes for your IDE.
Regarding the version: It is always nice to have the latest version on board (in python however there are compatibility issues to take into account) , since there might be features you want to use, that are only available with a certain version and upwards. Since this is sometimes tricky to find out, especially if you are new to the field, going with the latest version might be how you should proceed.
Be careful before installing new version of python.
Python has no backward compatibility.
Scripts written for python 2.7.* won't work on python 3
For example,
print "Hello" will work on python 2.7 but not on version3
How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.
EDIT:: im on a windows vista 64-bit
If you are on Windows, then just install another version of Python using the installer. It would be installed into another directory.
Then if you install other packages using the installer, it would ask you for which python installation to apply. If you use installation from source or easy_install, then just make sure that when you install, you are using the one of the proper version.
If you have many packages installed in your current python-3, then just make a zip backup of your current installation just in case.
Erm... yes. I just installed Python 3.0 on this computer to test it. You haven't specified your operating system, but I'm running Ubuntu 9.04 and I can explicitly specify the version of Python I want to run by typing python2.5 myscript.py or python3.0 myscript.py, depending on my needs.
Typically python is installed with a name like python2.6, so you can have more than one. There may be a symlink from python to one of the numbered files. Quite workable.
Yes, it is possible.
I maintain 3 python installations (2.5, 2.6, 3.0). The only issue that could be confusing is figuring out which Python version takes precedence in PATH variable (if any) . To execute a script for a specific version, you would go into the python directory for that version
C:\Python25\ , C:\Python26\, C:\Python30\, etc.
Drop the file in there, and run "python.exe file.py" from command-line.
You could even rename each python.exe to python25.exe python26.exe python30.exe and have each directory in PATH so it would be easy to execute any script on any version.
I would assume it'd be the same as running two versions of 2.x; as long as they're each in their own directory you should be OK.
You certainly can. On Mac Ports, there's a tool called python_select that lets you switch among python versions; if nothing like it exists on Windows (momentary googling didn't reveal one), it could certainly be written.
You can set up virtual python environments using virtualenv.