Difference between installing by pip and installing globally - python

I am workikng with Python/Django web application, in Amazon EC2 / Debian series operating system.
Application has Python setuptools library as dependency. So I installed setup this lib by this command globally:
sudo apt-get install setuptools
But this didn't work - application says dependency didn't resolved correctly. After some googling, I have found solution, like this:
pip install setuptools.
This worked for me.
But I have a question - what's difference between these two? Of course, I didn't activated virtualenv, so it seems setuptools is installed globally.
Would you like to bring me your experience? Please help me.

These are 2 separate package managers, that sometimes don't play well with each other.
# linux system level as root
(sudo) apt-get install
# inside of an more isolated python folder structure, that does not interface with the system level packages
(venv) pip install
You may* be able to install with all of the build tools:
sudo apt-get install python-pip python-dev build-essential
pip install --upgrade pip

sudo apt-get install setuptools this is too different from pip install setuptools.
Sudo apt-get install is use to install packages from Linux repository, and pip is for install libraries or packages for python. If you use virtual environments you install different libraries for each project read more about it here.

Related

How can I install DistUtilsExtra on Python compiled from sources?

I'm working on a Raspberry Pi. For some complex reasons I'd rather not get into, I had to remove Python2 and Python3 from the system, and compile Python 3.9.2 from scratch. Works great.
Unfortunately, now, I need Ansible to configure the system, which requires python3-apt if you plan to use a task that uses the apt module, which I do. python3-apt appears to just be python-apt, which I can install with pip.
Unfortunately, when I try that (pip install python-apt), I get this:
ModuleNotFoundError: No module named 'DistUtilsExtra'
If my python was installed with apt, I could just do:
sudo apt-get install python3-distutils-extra
But that depends on the python packages from the apt repos, so it will install Python from apt, which I don't want.
python3-distutils-extra appears to just be a python package, but I can't seem to find it on pypi. Is there a way to install it without using apt?
Or should I just tell apt to install the package, and ignore installing dependencies?
A possible workaround is to rebuild the wheel from the source code of the apt package
apt-get source python3-distutils-extra
cd python-distutils-extra-2.40
python3.9 -m pip install wheel # You'll need this to run setup.py
python3.9 setup.py bdist_wheel # Create the wheel
python3.9 -m pip install dist/python_distutils_extra-2.39-py3-none-any.whl # Install the wheel

I want to install pip for python3.6. When i allready have another version of python3 is installed.

But when i run command sudo apt-get install python3-pip. It is installed but inot as python3.6. It is installed in python3.5.I have also specified the version in command i.e sudo apt-get install python3.6-pip.But it gives me an error.
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6-pip
E: Couldn't find any package by glob 'python3.6-pip'
E: Couldn't find any package by regex 'python3.6-pip'
You can install python packages using python3.6 -m pip install [Package_to_install] straight away.
I use PipEnv for working in different environments with different python versions.
the usage would be something like pipenv --python 3.X and it will install that version of python if its not installed.
It also makes things really helpful if you are collaborating with other developers, because it creates a PipFile (alt to requirements.pip) which will contain the version of python used for the project so all developers will use the same version of python on a project without doing any prep work.
If you don't want to use pipenv you can use pip3.5 or create a python3.5 environment like virtualenv [NAME] --python=/usr/lib/python3.5 and then install the package using pip install somepackage
This will help you fix the above problem
You need to add following personal package repository:
sudo add-apt-repository ppa:deadsnakes/ppa
Check for updates
sudo apt-get update
install python using following command
sudo apt-get install python3.6
It was easy. I just changed my default python3 version:
sudo gedit ~/.bashrc alias python3="python3.6"
Now I can install the packages using python3.6 with
-m pip install 'packagenae'

How can I install ipython notebook on ubuntu 17?

I tried to install ipython notebook on my OS.But there was an error.How can I solve this?
sudo apt-get install ipython-notebook
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package ipython-notebook is not available, but is referred to by another packag.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'ipython-notebook' has no installation candidate
Do you already have python installed? If so, try:
sudo apt-get install ipython
or if you have pip:
pip install ipython ipython-notebook
Regardless, I instead recommend installing Anaconda or Miniconda from:
https://www.continuum.io/downloads
This will help you setup virtual environments and packages.
I installed ipython via apt, and then went the pip and virtualenvwrapper route for ipython-notebook, which worked for me. The commands were:
sudo apt -y install ipython
mkvirtualenv ipynb
pip install ipython[notebook]
Alternatively:
sudo apt -y install ipython
mkvirtualenv ipynb
pip install ipython[all]
FWIW, I ran into this error when trying to run the following command on a freshly spun up Ubuntu 18 image (on AWS, ami-0ac019f4fcb7cb7e6):
sudo apt-get install ipython3
E: Package 'ipython3' has no installation candidate
Running an apt-get update solved the problem. So:
sudo apt-get update
sudo apt-get install ipython3
Interestingly, I was surprised to find that this particular distro doesn't come with Python 2.7 installed, only Python3. That's probably AWS just trying to keep things light, which I appreciate.
Hopefully this helps someone down the line.
As virtually every Linux distro, Ubuntu comes with Python 2.7 pre-installed. In order to execute your Python code, you open your terminal, cd to the directory where the script is and run python script.py

How to download and install the pcapy package with pip?

I know that in order to install a package I need to execute:
sudo pip install package_name
But how can I know what is the name of package - I should give as an argument.
I found in pypi a package I want to install - pcapy:
https://pypi.python.org/pypi/pcapy/0.10.3
I tried:
sudo pip install pcapy
It didn't work...
What is the right way to install this package?
Thank you very much!
That package isn't in the PyPI. There's a page, but the source code is hosted elsewhere for some reason (this is the first time I've seen it):
Ubuntu has a (probably old) package:
$ sudo apt-get install python-pcapy
You can also build it from source:
$ sudo pip install "http://corelabs.coresecurity.com/index.php?module=Wiki&action=attachment&type=tool&page=Pcapy&file=pcapy-0.10.8.tar.gz"

python-pip yum package provides pip-python instead of pip

I installed python-pip package via yum (using Fedora's updates repo). It does not add the pip script to my PATH though.
$ which pip
/usr/bin/which: no pip in
(/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:
/usr/bin:/usr/local/sbin:/usr/sbin:/sbin)
It does, however, create pip-python:
$ rpm -ql python-pip
/usr/bin/pip-python
[...snip...]
$ which pip-python
/usr/bin/pip-python
I was considering making pip a symbolic link to pip-python but is there a reason the executable is named pip-python to begin with?
If you install the python-pip package and then run:
pip-python install -U pip
pip will fix itself.
It is probably to avoid a conflict with another package that has an executable called pip. As long as you don't install that package, you should be safe.
Another annoying example of this is the chromium browser, which my distro's executable is chromium-browser to avoid a conflict with some game I had never heard of until I did an: apt-get install chromium.
This used to be the case on Fedora, due to the conflict noted with the perl-pip package. With the gracious consent of the perl-pip packager, this has been updated in recent versions, so installing pip-python on Fedora 17 or later now installs /usr/bin/pip
See https://bugzilla.redhat.com/show_bug.cgi?id=958377 for details.

Categories