What is the difference between <package name> and python-<package name>? - python

I want to downgrade tornado to a previous version because the new one causes an error according to the answers here: Jupyter notebook kernel not connecting. I am on Ubuntu, in a virtual environment.
To check the current version of it, I used pip freeze and got this: tornado==6.0.1. When I use apt-cache policy tornado the output is: "Unable to locate package tornado". When I type apt-cache policy python-tornado the output is "python-tornado: Installed: 4.5.3-1".
How do I proceed from here? My ultimate goal is to make the jupyter notebook run, and I need to figure out this tornado module for that. What is the difference between tornado and python-tornado? Which one I should care about?

One of those names is the actual package name under which it is published to the Python Package Index (PyPI), which is the namespace that pip deals in.
The other is the name as set by your Ubuntu operating system, and given the version string, I am guessing that you are using Ubuntu 18.04 Bionic Beaver. Ubuntu uses a strict naming convention, where all Python packages must start with a python- prefix. These packages are managed and installed by your OS package manager.
How to proceed depends on your Jupyter setup. If it is installed and running from a virtualenv, then you can use the pip command when the virtualenv is active to alter versions there. Take into account that using pip should already ensure you are getting compatible versions installed; you could try to upgrade jupyter if tornado was upgraded independently.
If you are using the Ubuntu-managed jupyter package then there too the package manager should take care of matching versions.
However, if you you are using a virtualenv that still has access to the OS-mananged jupyter system while locally only tornado is installed, then you want to add jupyter to your virtualenv to mask the system version, which is too old.

Related

Is Anaconda necessary to be installed to PC besides Jupyter Notebook?

I am new to Python. I am a very old R programmer. One of my PhD courses is performed via Python.
So, I installed Jupyter Notebook; I wrote simple "Hello World" in Jupyter Notebook. I wonder whether I must install Anaconda or not?
I ask this because: I looked at Anaconda's IDE in youtube, and it shows RStudio, Jupyter Notebook, etc. in a bundled manner. In RStudio, one can perform all the package handlings within RStudio.
So, I wondered is there a way to install python packages within Jupyter Notebook, or should I really install Anaconda? What is the benefit of installing Anaconda (besides Jupyter Notebook)?
The packages in python are generally installed with "pip" (or "conda") in the terminal and are then available regardless where you run your script from. Assuming you don't have multiple python versions set up on your PC, they should then all be available in your jupyter-notebook also.
If you don't want to open another window to do this, you can also run BASH code from Jupyter itself, just start the line with an exclamation mark (!)
i.e.
!pip install pandas
The benefits of Anaconda are that it bundles everything you need to at least start your more basic projects (python release, basic packages, IDE) and that you can set-up project-specific environments that do not interfere with your system-wide package installations.
Python packages are not installed with python functions, like it would be the case in R with install.packages("package name"). Instead, an external package manager usually is used to install and possibly compile the package files to a directory where python can import it from.
Anaconda offers (among others) the package manager conda. Most popular is pip. Some Linux distributions also offer python packages via their package manager (e.g. apt on Debian/Ubuntu). All these package managers download packages from their own repositories, so conda install numpy, pip install numpy and apt install python3-numpy all install a package numpy, but from different sources and in possibly different versions.
Jupyter Notebook is a programming environment, where you can execute shell commands with !command, so depending on the system where the Jupyter server is running, you can use !pip install numpy, !conda install numpy or other commands as cells in the Jupyter Notebook you are working in. This will run the command in a shell.
That graphical menu with Jupyter, RStudio etc. you describe is the program "Anaconda Navigator", which is installed with Anaconda. Jupyter is just a Python library, which is pre-installed with Anaconda, but can also be installed via pip, apt and other package managers.
Like Virtualenv, Anaconda also uses the concept of creating environments so as to isolate different libraries and versions. Anaconda also introduces its own package manager, called conda, from where you can install libraries.
Additionally, Anaconda still has the useful interaction with pip that allows you to install any additional libraries which are not available in the Anaconda package manager.
It is a good option for setting up of a better environment for working with jupyter.

Setting packages version using pip in a conda environment

Background:
I've been working on a server last year as a part of a student project. Now the server is being changed and unfortunately, a piece of code that I'd written is failed to pass a test. I don't have access to the server (because of security issues) but the good news is I have the scripts as well as the packages (and their version) which are installed on the new server. So I've decided to install all the packages on the server on my own local machine in an environment to imitate the server.
Problem:
Since not all the packages are available with conda (or channels need to be specified) I decided to make a conda environment and install all the packages with pip. Once I create the environment, conda installs a bunch of packages (like wheel,pip,ipython, certifi, etc.). But I need a certain (older) version of them. So I tried to override them by pip install -U <package_name>==<version>. But for some packages, I ended up with two different versions: one the default version installed by conda at the environment creation, and the other one with pip. And now, when I run my code, I'm not sure which version of those packages are being used. So I want to keep only one version: the one which is installed via pip!
Question(s):
How can I uninstall the packages that are installed with conda while keeping the pip ones? I used conda remove <package_name> with the expectation that only conda-installed packages would be wiped, yet that wasn't the case and both were gone for good!
How to override a conda-installed version via pip? I know conda is made to avoid this action to protect the environment from getting messy, but in my case it leads me to another question,
How in the first place, can I make the environment exactly the same as the server so that I don't deal with conda/pip packages any more?

New python versions add to the existing ones, rather than upgrading

I'm new to python. I installed python3.4 on OsX some time ago and now I installed python3.5 using the installer you can download from the site.
I noticed that in /Library/Frameworks/Python.framework/Versions/ I have both 3.4 and 3.5. I wasn't expecting that - I was expecting an upgrade where 3.5 replaced 3.4
So, if I run python3.5 and I try to import the packages I installed when using 3.4, they are not found. Furthermore if I use pip install to reinstall them, it says the packages are already installed, therefore I can see that it's pointing to the 3.4 version.
What I'm doing wrong? I supposed that installing the new python should upgrade my existing installation (bringing installed packages with it) rather than add a completely new install.
I'm not sure what to do now:
Should I keep every old version?
Should I manually change which pip
is used every time?
(is there a more streamlined update procedure
for next time?)
A lot of Python packages are 3rd party. The community is always moving forward and this may take some getting used to!
That said, my recommendation is to start using venv. It gives you (mostly) isolated Python virtual environments in which you can install whatever packages you like (via pip) without polluting the global installation. This also allows you to configure various virtual environments with varying packages and versions. It's really handy!
Link:
https://docs.python.org/3.4/library/venv.html

Modify PYTHONPATH to install packages into new "site-packages" path

I am working on an EC2 VM running Linux (I'm fairly new to Linux and Bash) which comes installed with Python 2.6. I upgraded to Python 2.7. When I try to install new modules, they install in /usr/lib/python2.6/site-packages but I need to change this to install in /usr/lib/python2.7/site-packages. I've tried a bunch of different ways to update the PYTHONPATH which I've found in various other post on Stackoverflow and other sites, but to no avail. Some I've tried are:
PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/site-packages export PYTHONPATH
PYTHONPATH="/usr/lib/python2.7/site-packages:$PYTHONPATH"
How can I update the install path to the new 2.7 path?
You covered how Python 2.7 was installed (which is a manual installation), how are you installing your modules?
If you sudo yum install <python-package>, you are going about this using system level (distribution specific) way of getting packages installed, which means it will only put packages in the system python location, in your case in the site-package directory in python2.6.
If you had used sudo pip install <python-package>, it should possibly work since you completely destroyed the default python installation which yum might have need (refer to Upgrade python without breaking yum).
With virtualenv, you can specify isolated, local locations for which you can install python packages to, isolating them from system level and you can fix a virtualenv to any available versions of python on your system, guaranteeing the right sets of libraries with the right sets of packages with all the correct versions (for python and the packages) specific to the needs of a particular application, which means you don't have to deal with the system/distribution level python path issues as that can be a huge source of headache. For example, on the system level you have a package by your distro that depends on some old versions of sqlalchemy, but in your actual application you need the most recent version, with virtualenv you can mask out the system level package and have the latest version installed locally there.

Could I get a list of modules that I installed using easy_install?

Recently, I installed trac on my local machine for testing purposes.
To get it running, I needed to install several support modules using easy_install.
Now, I'm going to take my local installation and move it to a real server that has no Python installed yet.
While moving the trac installation itself seems trivial (http://trac.edgewall.org/wiki/TracBackup, https://serverfault.com/questions/6147/how-do-i-backup-my-trac-instalations), actually getting it running needs the modules that I installed with easy_install.
Is there a convenient way (such as for example PPM for Perl) that I could use in order to get the same modules installed on the server that I have on my local machine?
If you don't use pip, only use easy_install, try https://pypi.python.org/pypi/yolk
Install Pip, and then
pip freeze
You can also use help function in python to get the list of modules installed. Get into python prompt and type the following command.
help('modules')

Categories

Resources