I just installed ubuntu 18.04 and I really don't know how does everything work yet. I use the last version of python in my windows system (3.8.1) and would like to use that version as well in ubuntu, but the "pre-installed" version of python is 2.7. Is there a way to uninstall that old version of python instead of changin the alias of the python command to match the version I want to use? Can you do that or does ubuntu need to have that version? If you could help me or explain this to me I would appreciate it.
It's not a good idea to remove Python 2 from your Ubuntu 18.04 because maybe some services or apps are using it (Despite that Python 2 doesn't get support any more)
(In Ubuntu 19.10, we have only Python 3)
The best answer is using Virtual Environments that make an isolate work station for you with any thing you wish, and it doesn't mess with other platforms.
Some services and application in Ubuntu use Python 2.x to run. It is not advisable to remove it. Rather, virtual environments maybe a good practice. There, you can work on Python 3.x, as per your needs, without messing up with the system's dependencies.
Related
It seems I have several Python versions installed on my Mac (High Sierra). Do I really need more than one each of Python 2.7 and the most recent Python3?
I am primarily concerned about confusion when adding modules to the environments.
Here are the python executables I can find, excluding symlinks. Do I need them all? Does Apple need one version just for the OS? (Maybe that's Ruby I'm thinking of._)
/usr/bin/python
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/Cellar/python/2.7.13/bin/python
/usr/local/Cellar/python/2.7.13/share/python
/usr/local/Cellar/python/3.7.1/libexec/bin/python
On MacOS, you need to have the system-installed Python 2 in /usr/bin/python because some system functionality depends on it.
If you have other versions installed via Homebrew or etc, that's strictly optional. For developing code in Python, definitely install a recent version of Python 3; you should not be developing new code in the legacy version 2. It will run out of support in a year or so, and many important third-party libraries etc have already abandoned support for it.
If you do need to maintain Python 2 code, having a Homebrew version of the most recent Python 2.7.13 is probably a good idea. The system /usr/bin/python is at version 2.7.10 as of MacOS Mojave; and if we extrapolate from Apple's update policy history for third-party open-source software in the system, it will probably remain there for many years.
Homebrew is just one of many ways to install additional Python versions, but since this is what you seem to be using already (as indicated by the /usr/local/Cellar paths) I will not go into alternatives.
For switching between versions, virtualenv is the common baseline, though there are many add-ons like pyenv etc which add convenience features or alternative models for switching between projects which require different versions of Python and various packages.
Note: this answer might be primarily based opinioned.
First, in macos, I encourage you to use brew to install python. So, if you want to instal Python 3 run:
$ brew install python
Probably it is already installed, so to update it run:
$ brew upgrade python
This will upgrade to the latest version of Python 3. In general, if you start a new project you should use Python 3. Remember that Python 2 will be deprecated at the end of this year 2019.
Second, I highly recommend you to use virtual environments to avoid having issues with dependencies. You can create a virtual environment running:
$ python3 -m venv .ven
This will create a virtual environment in .venv in your current working directory.
As an alternative you can use pipenv to track dependencies too which I also encourage you to install using brew.
$ brew install pipenv
Then you create a virtual environment running:
$ pipenv --three
Keep in mind that you will have two versions of Python in your machine python which is Python 2 (installed by default in your machine) and python3 which is Python 3. Then, if you want to run Python 2 just type python, while if you want to run Python 3 type python3.
Finally, you can also keep track of several python versions using pyenv. This is very useful if you need to use multiple versions of Python for example Python 3.1, 3.2, 3.3..., 3.6, 3.7.1, 3.7.2, 3.7.3, etc.
This is what has been useful in my experience using macOS. You could also use Docker to completely isolate your environment, but probably the first two points is enough if you are a beginner.
While Python 3.x is what python solutions should be implemented in today, many existing python applications, modules, etc, are implemented and maintained in 2.7 or lower. Sometimes you'll find multiple versions of python on your computer because applications you've downloaded in the past had you install them so their application would work properly on your machine. As long as you don't want, or need applications that may depend on past versions of python, you can update to the latest one and delete the old versions.
If you are planning on developing in python, and you can use the latest version, you should definitely do so. If you rid of the versions of python on your machine, applications, modules/scripts, etc may not work or function properly.
Python comes pre-installed on Mac OS X, but it is not required to be on your machine for your computer to function, just the applications that may be on your machine that may use Python.
I'm newbie of python programming.
I have windows 7 laptop and I'm also running virtual box Ubuntu.
I manually installed python3.5 on Win7 through Eclipse first. The default python version in my Virtualbox Ubuntu is 2.7.11.
Is it possible for me to install python packages through my VirtualBox to my Win7 python3.5?
Will it bring any problem with multiple versions of python.
python 3.5 packages do not work with python 2.7 and vice versa.
And I even think that you can't install packages from linux to windows.
I think what you wish to accomplish is to have a same version Python across both machine.
Best way is to go about doing it is to either install Python 2.7.x on Windows 7 or upgrade python 2.7.x on your Ubuntu to Python 3.5.x. Neither is good or bad.
To upgrade your Python 2.7.x to 3.x.x on your ubuntu machine,follow the instructions here.
If you wish to wish to install Python 2.7.x on your Windows,simply download the compatible exe from official page .It will create a folder under c: e.g. C:\Python27 .Thereafter,add the python path to environment variable PATH.
As for installing packages,the command remains the same across both OS.
pip install <package-name>
Usually packages have dedicated versions for different python versions.pip install will automatically resolve versions and install the compatible package version.
The Ubuntu VirtualBox is not just a linux-looking frontend to your existing Win7 install. It's a completely separate OS that runs as if it were on a separate computer. You can set up shared folders to share data between the host and guest, but trying to use Linux to install programs on Windows would be error-prone and risky even if you could do it.
If you plan to be using Python on Windows, you'll need to install the packages on Windows, and a Linux VirtualBox isn't going to help you with that at all. If you're uncomfortable with the Windows command line, read up on some tutorials. There are also some alternative Windows shells that provide some advantages over the built-in CMD.
If you'd rather work on Linux, you can do that, but you'd want to do it entirely inside the VirtualBox. Inside Linux, you could install the version of Python you want, install the packages you want, and use whatever dev tools you want, as if you were working on a Linux computer. (Although in this case I have to wonder why you aren't actually using a Linux computer instead of a Windows one.)
I have python 2.7.6 and 3.4 on my mac installed currently. I want to upgrade python2 to python 2.7.8 as I believe it is the more secure. What is the right way to do this? Do I simply download the installer from the website and run it? If so, will my system automatically use 2.7.8 over the previously installed 2.7.6?
Note, the python version 2.7.6 came pre-installed. And I apologize if the question seems redundant. I used to develop blindly without any thought of the versions and packages and made a mess of my projects. So now I try to careful.
pyenv is a simple Python version management. You can find more on pyenv.
Supposedly Python 2.7 is included native to OSX 10.8 and above (if I remember correctly), but I recently installed Python 3.5 to use for projects while I work through UDacity. Lo and behold, the UDacity courses seem to use 2.7 - wups! So instead of trying to uninstall 3.5 (this procedure seemed to scary for neophytes such as myself), I simply installed 2.7 in addition to the recently installed 3.5 and just run the 2.7 IDLE and Shell. Is this ok, or will I run into problems down the road?
I have installed two versions, 2.7, 3.4 and I do not have any problem by now. 3.4 I am using for my work project in eclipse environment, 2.7 for udacity course, like You ;).
As long as you keep your installation folders organized, you should have no issues having both on your computer, besides one thing. The path environment variable for python will determine which version is used by default, so I would say stick to one version, or make sure to make your programs as backwards compatible as possible. I have run into this issue on Windows, since I installed Python 3.4 before 2.7, and therefore to run older code, I have to manually select the python executable. In terms of libraries, I believe that for each python version, the libraries are completely separate, so you should be good there.
As others have said, if the installation directory is different it should be no problem at all.
One thing that'll make your life easier for switching between the two is to use an IDE such as PyCharm, you just have to change a drop down to switch between the two versions.
It should be fine. Its actually pretty common to have multiple Python environments. It helps to prevent dependency conflicts between your projects. That is what is happening when you are using tools like pyenv and virtualenv.
Using tools like pyenv and virtualenv may also help you with the path problems that others mentioned. They have commands to set up the path so that their version of pip, python, etc are used.
Im not sure about OSX, but with windows 10 my environment variables for 2.7 were overwritten with the 3.5 path. Not a tough fix, but a little confusing, since it was months later when I needed 2.7 again.
You can also use Anaconda for maintaining two versions of Python:
Download Anaconda for both Python versions
Open .bashrc
Add the path to new Anaconda you have installed for, e.g.:
export PATH="/home/paras/anaconda3/bin:$PATH"
Now there will be 2 export paths: one for Python 2 and one for Python 3. Comment the one which you don't want.
I have the same problem and it is not necessary to uninstall on version of python. Please take care to not mix them up - When you search them up on the start menu. You can make a desktop shortcut saying 2.6 and 3.5.
Which linux distro is better suited for Python web development?
Background:
I currently develop on Windows and it's fine, but I am looking to move my core Python development to Linux. I'm sure most any distro will work fine, but does anyone have any reasons to believe one distro is better than another?
Largely distribution won't matter, as Python is present and largely self sufficient on virtually all Linux distributions.
If you're wanting to focus on development, I'd recommend Ubuntu. Ubuntu is arguably one of the most fully featured "ready for the user" distributions that makes system administration a snap, so you can focus on the development tasks you want to tackle.
If you have a Linux environment that's a target for your code (like say, RedHat or something), then go with the desktop distribution that matches your target environment (like, say, Fedora for RedHat, Gentoo for Gentoo, Ubuntu for Ubuntu Server, etc.)
Otherwise, all of them are suitable.
You distribution should have Python 2.6. Otherwise it's a matter of choice.
One advice: Never ever install anything as root (eg. python setup.py install). Only install things with your distribution's package manager and use virtualenv as a user to install other packages.
Ubuntu has a virtualenv package and it can even be used without being installed.
Using a distribution with the latest stable versions of Python only lets you test your code with those versions. Today it's very easy for developers to test their code with multiple Python versions.
Gentoo probably gives you the most flexibility with multiple Python versions installed at once:
(2.5) 2.5.4-r4
(2.6) 2.6.6-r2 or 2.6.7-r2
(2.7) 2.7.2-r3
(3.1) 3.1.4-r3
(3.2) 3.2.2
That doesn't let you test on some older versions that are very popular on Debian based systems, for example.
pythonbrew lets you compile and install multiple Python versions in your home directory, no root access needed.
It's a snap testing your code with multiple versions of Python thanks to 'tox'. By default, tox will find your system python(s), but you can set custom interpreters you build with pythonbrew, for example.
Here's a tox.ini you can use with Jenkins, for continuous integration. With this setup you can install jenkins then 'su - jenkins' and use pythonbrew to install all the Python versions you want to test.
[tox]
envlist = py267,py271,py272
[testenv]
#You may need to change this. Are your tests here?
changedir=tests
#You can also use nose, etc., see documentation
deps=pytest
commands=py.test --junitxml=junit-{envname}.xml
[testenv:py272]
basepython=/var/lib/jenkins/.pythonbrew/pythons/Python-2.7.2/bin/python2.7
[testenv:py271]
basepython=/var/lib/jenkins/.pythonbrew/pythons/Python-2.7.1/bin/python2.7
[testenv:py267]
basepython=/var/lib/jenkins/.pythonbrew/pythons/Python-2.6.7/bin/python2.6
It's that easy, and it doesn't matter which Linux distribution you use.
See the Tox website for details on configuring Jenkins.
I use RHEL and have been very happy, so from that I would say Fedora would be fine. I use Debian at home, and it's great (headless though, so no web there).
That said, I think you should probably just pick one based on what your company uses, or any number of non-Python reasons. I don't think you are going to find Python tool availability an issue with any Linux distribution.
Most major distributions will include Python and Apache, so it's really just a matter of choice. If you're new to Linux, I'd suggest either Ubuntu or Fedora. Both are great for new users and have excellent community support.
As the other answers have mentioned so far, the Python 2.6 interpreter will be available on all recent Linux distribution releases. That shouldn't influence your choice.
However, your choice of IDE may eliminate some possibilities. You should make sure the distribution you select has a package for the latest version of your IDE, and that it is updated often enough.
As an example, I like to use Eclipse with PyDev for developing Python apps in either OS, but Ubuntu's official repositories had only Eclipse 3.2 (from 2006) until October of last year, when they finally updated to 3.5 in the latest distribution.
I am working with Python on Cento 5.4 and Fedora 12 and I am very happy.
I also use Eclipse IDE for python and other languages without having any major issues.
Any desktop distribution like Ubuntu, OpenSUSE, Fedora, ... is OK, But if you want to always have the latest versions, I recommend ArchLinux.
i think i remember a podcast with Guido Van Rossum and his core team python developers back in the days, and one of that core python developer is now employed by Canonical to take care of python integration for the ubuntu distro. So that explains why ubuntu is a much more pythonic distro compared to other distro.
On the other hand, the gentoo linux distro also has python integrated in its Portage package management system. So gentoo and ubuntu I would say are good for python development system and each represent both ends of the spectrum.