Install 2 python versions linux - python

So one of our servers has v2.6 installed. I’ve checked and most of the scripts that runs in this server are unix scripts. There are few python scripts but I’m not sure if it’s still being used. They are not in cron. I don’t know their users as well.
Now I want to install another version which is v3.10. In short there will be two versions in the server — v2.6 and 3.10.
My question is — is there a chance that those scripts running in v2.6 will encounter any issues once we install v3.10?

If these scripts explicitly point to your python 2.x interpreter (with a shebang), then no, you won't have any issues.
However, if your question is : 'will my scripts written for python 2.x run without issue within python 3.10', then the answer is it depends.
Some python2 will run perfectly fine with python3.
Note that even if you install python3.10 on let's say Ubuntu, then python will still refer to your python2 installation by default.

Related

Is SimpleHTTPServer available if Python is installed?

I am working on a small education project which will use Python SimpleHTTPServer from a shell script to serve static files from a folder like this:
python -m SimpleHTTPServer
I am not sure on which platforms the project will be run.
I don't think users will run it in some exotic environments - generally OSX, Linux, Windows.
Will it be enough to write in docs that Python is required to run it?
No, this will not be sufficient in 2018, and even less so in the future. You should tell them to use python3 -m http.server, and that Python 3 is required, but with a note saying they can use SimpleHTTPServer from Python 2 if they have that instead—and probably mentioning than Mac users do already have Python 2 instead.
(I'd like to say that you can get away with ignoring Python 2 entirely, because anyone who chooses to use it ought to know what they're doing by this point, but thanks to OS X, you can't quite get away with that yet.)
Windows: Users who go to python.org to install Python will be presented with 3.6 as the first choice, and 2.7 as the second choice. And in a year and a half, 2.7 will likely be moved to the "old versions" page along with 3.5 and 2.6.
Mac: Python 2.7 comes preinstalled. If they go to python.org, or use Homebrew, they'll be presented with 3.6 as the default, but if they know that they already have Python, they won't try that. And Apple may well keep shipping 2.7 long beyond 2020.
Linux: Current versions of most distros have 3.x preinstalled, and some do not have 2.x. And in a year and a half, most of the big ones are planning on relegating 2.x to community-package status. However, there are plenty of people still using older "Long-Term Support" versions of their distros, and these will continue to support (and maybe pre-install) 2.7 until they go out of support, which ranges from 2-8 years from now.
SimpleHTTPServer is only available on Python 2.x.
For 3.x you need to run it as python -m http.server.
Also, it might be worth mentioning that you can add port as an extra argument. (python -m http.server 1234 or python -m SimpleHTTPServer 1234)
Referring to in in the documentation should be enough I guess.
Linux and OSX should come with python preinstalled. (As far as I know).
For windows this isn't always the case. Some installations do, some don't.

Upgrade Python version while running a Python program

I would like to upgrade my Python version from 2.6.6 to the newest version of 3.6.5 on a server. However, there is a program that has been running for multiple days and will be running for a week or more.
Will my program continue to run until it finishes if I upgrade my Python version?
P.S.: I ran my Python program with the screen command so I wouldn't have to stop it to be able to upgrade my Python version.
Yes, your Python 2 script should continue to run while you install/upgrade Python 3, since Python 2 and 3 are different programs.
However, the installation will be be platform specific and there might be common dependencies, so I would test this on a different machine (e.g. local virtual machine) first.
Several aspects are to be considered here:
In general, a Python program that is running does not access the installed binaries of the interpreter anymore. Also all the modules already loaded will not be read again from disk during the execution time of this program. (In this aspect it differs from e. g. a Bash script which reads its script source while executing.) So you probably are safe in even removing the complete Python installation; of course that's not what you plan on and I wouldn't recommend it for other reasons, but even that should not influence your running Python program. If, however, your running Python program tries to import a module for the first time after the removal or upgrade of your Python installation, this might fail due to incompatibilities between the versions. Most programs do their imports only at the beginning of their runtime, though.
Python 2 and 3 are different languages. Scripts for the one need to be at least adjusted to run with the other. Adjustments aren't too hard to do, though. Most distributions have both installed side-by-side. Most of the time, Python2 is still standard (and accessed by typing python). python2 and python3 are then to make it explicit. This means that you probably should not remove Python 2 from your system, even if you plan on installing Python 3. There probably are scripts relying on the installation of Python 2.
There's a lot going on here that you've not explained/described, so it's hard to give you a definitive answer (such as the operating system you're using). This is also not exactly a programming question, so you might find that the question gets voted to close. That said...
It possible to run multiple versions of Python side by side. Because 2.x and 3.x are very different, it might be much better to have both versions installed. See this answer for some details on doing that:
Official multiple Python versions on the same machine?
It's likely that your code will need some modifications to run on Python 3, so you're going to have to redeploy a new version of your code at some point anyway.

Install python3 beside Enthought Canopy

I'm developing python code that needs to run under 2.6+ and 3+ (I'm using python-modernize to make the code compatible). The code under development has no C extensions or 3rd party Python package dependencies except for pexpect3.3 which is used solely for testing.
How can I install python 3.4 on OS X 10.9.5 for the sole purpose of testing the code under development, i.e. I want to be able to run 'python3 myscript.py' but otherwise be sure that python3 will not be invoked as 'python' and without compromising the Enthought Canopy python2.7 environment that's my day-to-day standard for all other python work?
I'm aware, from other SO answers, e.g. Python 3 in Enthought Canopy, that Canopy doesn't support 3.x, so I'm not trying to make it work in that environment. I just need 3.x for some command line testing.
Should be no problem at all. Just ensure that your Python 3 is not set at installation to be the default Python in Terminal (i.e. not on PATH). And if for some reason it does end up in PATH, hunt it down and remove it from your ~/.bashrc, ~/.profile, ~/.bash_profile. I prefer to have no default python and only to set it into PATH as needed using an alias.

Will installing new version of Python conflict with old versions

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

Modules between multiple versions of Python Linux

I have Python2.6.5 and Python2.4.4 on my linux machine.
At the moment, all the modules I have (wx, ply, pyserial, twisted, to name a few) are installed for the 2.6 version of python. If I try to import wx on Python2.4, I get the expected no module error.
The problem here, is that I have a lot of devices (Let's say over a thousand) all running 2.4.4, which will soon need to be supported by this machine (For builds of code, releases etc). Until now, I've been using an EeePC (Same device as the ones I'm supporting) to do builds and releases, which has worked well. (I develop on the 2.6 machine, and build on the EeePC).
How would I go about getting these modules to work for Python2.4? I've tried reinstalling (With 2.4 as my primary), but that just caused errors. The blogs/answers I've found say to use easy_install, but that doesn't support the packages I need (Or at least, it just died when I tried).
In short: I'm currently using python 2,6, but I'd like it to change to 2.4 for all the modules as that's what I'm going to be using.
You can't share modules between different versions of Python. If you want to use wxPython from Python 2.4, you need to install it for Python 2.4.
You said you tried to install it with Python 2.4 as your "primary". I'm not sure what that means. You would install wxPython for Python 2.4 by running the installer with Python 2.4, like so:
$sudo /usr/bin/python2.4 setup.py install
Or similar.
You can use easy_install as well, but then you need to install Distribute for Python 2.4 first. Did you do that?
I recently wrote a full explanation on my blog about this: http://regebro.wordpress.com/2011/02/02/newbie-hint-on-installing-python-and-its-modules-and-packages/
Don't attempt to share them; this has some chance of success with pure Python modules, but C modules will fail to work. Instead, install them using the appropriate interpreter executable, e.g. python2.4 setup.py install.

Categories

Resources