Installs a new version of Python conflict with older versions

I'm a newbie programmer just installing Python 3.2, but I know that I also have an older version of Python on my machine. In fact, I think the Macbook comes with it installed. Do I have to worry that I have different versions on my computer when I try to start learning Python?

+4
source share
7 answers

For the most part, you don't need to worry about conflicts with the Python system. It is actually recommended that you install a different version of Python instead of working with the Python system. Also consider using virtualenv and virtualenvwrapper to maintain any dependencies for each project easily without conflict.

+3
source

Actually it depends on what OS you are talking about. I assume you are talking about a Mac since you mentioned a Macbook.

Macs comes with 2.5 and 2.6 installed, as far as I know. At least I have both versions, and I only installed 2.7 manually.

You can check which version of python is the current "system" python by doing the following in a terminal:

 // check the version of system python python --version // tells you where the system version of python is on your PATH which python 

On operating systems such as * nix, such as Macs, applications are not actually installed, as on Windows (details). Instead, application files are located in different parts of the file system. For example, Python is placed in the following directory (default) when installing 2.7:

 /Library/Frameworks/Python.framework/Versions/2.7/bin/python 

Since this directory is not located on the PATH system, this version of python will not be used when you simply call python from the command line. The system will look for all the folders in the PATH environment variable for the executable called python. Usually he will find it in /usr/bin/ or something similar.

To create a new version of Python for the python "system", you have several options:

  • Modify your .bash_profile and add the path to the new python to the PATH environment variable.
  • symlink new version of python to a directory already on your PATH, for example / usr / bin /

Remember that Mac python installers can modify your .bash_profile (in your home directory) so that the new version is a standard version of the system. Here 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. The private version is usually the default, and that any python executable is located on the PATH in the first place.

If you want to use a different version at any given 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 

This will execute some_script.py script in three different versions of python. Of course, you must make sure that / path / to / python is correct.

So, you should remember which version of python you are going to use, I hope this helps you understand how applications are installed and which version of the application starts by default when you do not provide a path.

+4
source

Yes, Python 3.x syntax is not backward compatible with 2.x. Therefore, if you learn Python 3.x, you cannot transfer your knowledge to Python 2.x.

In addition, you must choose whether you want to learn 3.x or 2.x. 2.x is much more common than 3.x, but 3.x is the Python header. There is no more innovation in 2.x, and in the medium term, most frameworks will be ported to 3.x (now there are some notable exceptions )

Hope this helps!

0
source

In general, everything should be fine. Since the Mac is based on BSD, it must support the python command, indicating the version your system requires, usually an older version, such as 2.5. You may need to use a command such as 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 start using virtualenv to support individual Python installations for multiple projects.

0
source

A version of Python 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 computer. However, you cannot have versions with the same major and minor numbers installed at the same time (at least not without tricks), so you cannot have 2.5.2 and 2.5.4 at the same time.

Note that you will need to install any third-party libraries once for each version of Python.

0
source

It is very convenient to have several versions of python on your computer. Just make sure that if you call python in your console, it uses the python that you want to use. The same goes for your IDE.

As for the version: it is always nice to have the latest version on board (in python, however, there are compatibility issues that need to be considered), because there may be functions that you want to use that are available only with a specific version and up. Since it is sometimes difficult to understand, especially if you are new to this area, then with the latest version it may happen how you should continue.

0
source

Be careful before installing a new version of python.

Python is not backward compatible.

Scripts written for python 2.7. * will not work on python 3

For example, print "Hello" will work on python 2.7, but not version3

0
source

Source: https://habr.com/ru/post/1346736/


All Articles