How to properly update requests in Ubuntu 14.04 - python

I am currently using a python package that depends on requests 2.7.0 or greater, but the requests in my system, Ubuntu 14.04, is version 2.2.1. I tried to upgrade via pip:
pip install requests==2.7.0
but it gives me an error, saying:
Not uninstalling requests at /usr/lib/python2.7/dist-packages, owned by OS
I tried to upgrade it by using apt-get install --only-upgrade python-requests, but it says that it is already on the latest version (and it's not).
Then I tried to install in a virtual env, but it gives the same message as the pip message above.
Finally, I thought about two options:
1-) Uninstalling via apt-get and then installing via pip - I think it's too risky, since it will uninstall a lot of other packages.
2-) Cloning from github and manually installing via setup.py, but I also fear that it may mess with other packages depending on it
What is the best way to do it? Is there something simple I am missing?

This works for me on Ubuntu 14.04:
~ › sudo apt-get install -u python-requests
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-requests is already the newest version.
python-requests set to manually installed.
0 to upgrade, 0 to newly install, 0 to remove and 15 not to upgrade.
~ › python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.0.1'
>>>
~ › mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.
~ (test) › pip install requests
Collecting requests
Using cached requests-2.9.1-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.9.1
~ (test) › python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.9.1'
>>>
I wonder why your OS/Ubuntu version of requests is 2.2.1, whereas mine is 2.0.1. Have you installed a newer version of requests manually, via some other mechanism than the official python-requests .deb package? As suggested by #wilbur in the comments above, is it possible you have run sudo pip install requests at some point in the past? If so, it might be worth running sudo pip uninstall requests to see if you can get rid of it...

I needed requests >2.10.0 for socks proxy built-in support.
Force uninstall
dpkg --remove --force-depends python-requests breaks apt (even if requests is pip installed).
apt-get install python-requests rolls it back to 2.2.1, the maximum version in trusty repo.
However, yakkety ubuntu repo contains 2.10.0 python-requests, as needed, so i did the following:
apt-add-repository "deb http://us.archive.ubuntu.com/ubuntu/ yakkety main"
apt-get update
apt-get install python-requests # it installs 2.10.0
apt-add-repository -r "deb http://us.archive.ubuntu.com/ubuntu/ yakkety main"
apt-get update
Note! It is essential to do the second apt-get update to remove yakkety index not to execute apt-get upgrade occasionally and break your system.
So now I have the required version.
$ sudo pip2 show requests
---
Name: requests
Version: 2.10.0
Location: /usr/lib/python2.7/dist-packages
Requires:

Related

"No module named scipy" on Windows

In sklearn\base.py, I have the statement from scipy import sparse.
I am getting this error "no module named scipy".
I tried to install using pip install scipy, but I get so many errors:
libraries mkl_rt not found
openblas not found
lapack not found
no lapacl/blas resources found
etc.
What should I do on Windows?
I found this solution after days.
Firstly which python version you want to install?
If you want for Python 2.7 version:
STEP 1:
scipy‑0.19.0‑cp27‑cp27m‑win32.whl
scipy‑0.19.0‑cp27‑cp27m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp27‑cp27m‑win32.whl
numpy‑1.11.3+mkl‑cp27‑cp27m‑win_amd64.whl
If you want for Python 3.4 version:
scipy‑0.19.0‑cp34‑cp34m‑win32.whl
scipy‑0.19.0‑cp34‑cp34m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp34‑cp34m‑win32.whl
numpy‑1.11.3+mkl‑cp34‑cp34m‑win_amd64.whl
If you want for Python 3.5 version:
scipy‑0.19.0‑cp35‑cp35m‑win32.whl
scipy‑0.19.0‑cp35‑cp35m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp35‑cp35m‑win32.whl
numpy‑1.11.3+mkl‑cp35‑cp35m‑win_amd64.whl
If you want for Python 3.6 version:
scipy‑0.19.0‑cp36‑cp36m‑win32.whl
scipy‑0.19.0‑cp36‑cp36m‑win_amd64.whl
numpy‑1.11.3+mkl‑cp36‑cp36m‑win32.whl
numpy‑1.11.3+mkl‑cp36‑cp36m‑win_amd64.whl
Link: click
Once the download finished, go to your directory.
For example my directory:
cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip install [where/is/your/downloaded/scipy_whl.]
After that installation
STEP 2:
Numpy+MKL
From same web site based on python version again:
After that use same thing again in Script folder
cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip3 install [where/is/your/downloaded/numpy_whl.]
And test it in python folder.
Python35>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
Download the scipy wheel file from the following link
https://pypi.python.org/pypi/scipy
Then do pip install with the Downloaded file
pip install <wheel-file>
if required , provide sudo permission
I face same problem when install Scipy under ubuntu.
I had to use command:
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo pip install scipy
on CentOS
$ yum install lapack-devel
$ sudo pip install scipy
numpy should be installed before installing scipy. I face this issue when I was running only with numpy. First install numpy and then install scipy. It worked for me.
pip install numpy
pip install scipy
It will display a message like this.
Requirement already satisfied: numpy>=1.8.2 in
(from scipy)
Hope this would be helpful. :)
I have never successfully pip'd a scipy install, instead I have found it easier to install all the base dependencies. Check here for your OS
I've never tried this on windows, but the linux installs have always worked for me.

Brew is not able to find dependency in spite of it being installed

Brew is not able to find dependency inspite of it being installed.
dependency 'urllib2_kerberos' is already installed yet homebrew throws the message
Homebrew does not provide special Python dependencies; install with: pip install urllib2_kerberos
Here are the setup steps:
$ sudo pip2.7 install urllib2_kerberos
Requirement already satisfied (use --upgrade to upgrade):
urllib2_kerberos in
/usr/local/lib/python2.7/site-packages/urllib2_kerberos-0.1.6-py2.7.egg
$ sudo pip2.7 install urllib2_kerberos --upgrade
Requirement already up-to-date: urllib2_kerberos in
/usr/local/lib/python2.7/site-packages/urllib2_kerberos-0.1.6-py2.7.egg
$ brew install post-review
post-review: Unsatisfied dependency: urllib2_kerberos Homebrew does
not provide special Python dependencies; install with: pip install
urllib2_kerberos Error: An unsatisfied requirement failed this build.
Also tried
$ /usr/local/bin/python2.7
It successfully imports
Python 2.7.12 (default, Jun 29 2016, 14:04:44) [GCC 4.2.1 Compatible
Apple LLVM 7.0.2 (clang-700.1.81)] on darwin Type "help", "copyright",
"credits" or "license" for more information.
>>> import urllib2_kerberos
(Note: post-review is not on http://braumeister.org/ .
I tapped into another formula repo)
Just encountered this problem myself. The solution is making sure the dependencies are available in your path.
In my case, I'm running with Anaconda Python and had anaconda2/bin in my path but not anaconda2/lib.
I added the following to my zshrc:
export PATH="/Users/$ME/anaconda2/lib/python2.7/site-packages:/Users/$ME/anaconda2/lib/python2.7:/Users/$ME/anaconda2/lib:$PATH"
Then source ~/.zshrc (or your respective shell resource file) and you're good.

How do I install python3-gi within virtualenv?

I'm following the Python GTK+ 3 Tutorial and I'm trying to get a working install running in virtualenv. I have python3-gi installed through the Ubuntu package manager already. Things look like this:
:~$ mkvirtualenv py3 --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in py3/bin/python3
Also creating executable in py3/bin/python
Installing setuptools, pip...python
done.
(py3):~$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'gi'
>>>
(py3):~$ deactivate
:~$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
As you can see, python3-gi is obviously not available within virtualenv but I am not sure how to install it since python3-gi is installed through my package manager and not with pip.
It is now possible to resolve this using vext. Vext allows you to install packages in a virtualenv that individually access your system packages. To access gi, do the following:
pip install vext
pip install vext.gi
Update 2018 – Debian Stretch
Install GTK+ 3 / GIR.
apt install libcairo2-dev libgirepository1.0-dev gir1.2-gtk-3.0
Create a virtual environment.
python3 -mvenv venv
Install pygobject (pycairo should come as a dependency).
venv/bin/pip install pygobject
Update 2018 – macOS
Install GTK+ 3 and Gobject Introspection with Homebrew.
brew install gtk+3 gobject-introspection
Create and activate a virtual environment.
python3 -mvenv venv
Install pygobject (pycairo should come as a dependency).
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig ARCHFLAGS="-arch x86_64" venv/bin/pip install pygobject
Original answer
This is what I did to get GTK+ 3 within a Python 3.5 virtual environment on OS X 10.11.
Install GTK+ 3 with Homebrew.
brew install gtk+3
Create and activate a virtual environment.
pyvenv-3.5 venv
source venv/bin/activate
cd venv
Install pycairo on the virtual environment.
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig
curl -L https://cairographics.org/releases/pycairo-1.10.0.tar.bz2 | tar xj
cd pycairo-1.10.0
export ARCHFLAGS='-arch x86_64'
python waf configure --prefix=$VIRTUAL_ENV # It's ok, this will fail.
sed -i '' '154s/data={}/return/' .waf3-1.6.4-*/waflib/Build.py # Bugfix: https://bugs.freedesktop.org/show_bug.cgi?id=76759
python waf configure --prefix=$VIRTUAL_ENV # Now it should configure.
python waf build
python waf install
unset ARCHFLAGS
cd ..
Install pygobject on the virtual environment.
export PKG_CONFIG_PATH=$VIRTUAL_ENV/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
curl -L http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.12/pygobject-3.12.2.tar.xz | tar xJ
cd pygobject-3.12.2
./configure CFLAGS="-I$VIRTUAL_ENV/include" --prefix=$VIRTUAL_ENV
make
make install
cd ..
Profit.
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import Gtk, Gdk, Pango, GObject
>>> from cairo import ImageSurface, Context, FORMAT_ARGB32
>>>
Python 3.5 downloaded and installed from PSF.
I haven't found a proper solution to this. When I run into situations where I can't get something to install into a virtualenv directly, I symlink it there and it works fine (there are probably exceptions, but this is not one of them).
ln -s /usr/lib/python3/dist-packages/gi /path_to_venv/lib/python3.4/site-packages/
Not elegant in the slightest; seems nicer than giving the virtualenv full access to all system packages though (via --system-site-packages).
The pip package name is somewhat counterintuitive - use pip install PyGObject.
I installed pgi via pip, which may be an option. It is apparently API compatible with PyGObject and so far seems to work ok running Gtk.
On Ubuntu (tested in 19.04), you can download the package and then install it as follows:
apt-get -y download python3-gi
dpkg-deb -x <package>.deb <virtualenv path>
In Ubuntu, the name of the downloaded package is python3-gi_3.32.0-1_amd64.deb.

Installation of nltk-3.0a3 for python3.3.3 - "ImportError: No module named 'setuptools'"

I have installed Python 3.3.3 with a command:
sudo apt-get install python3
I am calling it as Python3, because I have Python 2.7 installed as well.
I have also installed distribute (setuptools) with a command:
sudo apt-get install python3-setuptools
To be sure, setuptools are installed for python3, I have searched with pip3 and I received an output:
$ pip3 search setuptools
setuptools - Easily download, build, install, upgrade, and
uninstall Python packages
INSTALLED: 2.0 (latest)
Now I want to install NLTK's version for Python 3, so nltk3.0a3. I have downloaded it from the official site, and in the folder I ran a standard python installation and received an output:
$ python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 33, in <module>
from setuptools import setup, find_packages
ImportError: No module named 'setuptools'
And in fact, when I go to python3 command line, for that input, I see the output:
>>> help('modules setup')
ez_setup - Bootstrap setuptools installation
setup
unittest.test.test_setups
So there is really no module called setuptools...
Does anyone know what am I doing wrong? Or is there any other way of installing NLTK for python 3? (in apt, there is only NLTK for python 2).
Thanks a lot guys for any effort!
You can use muon or your favorite package manager to install python3-setuptools and an experimental version of nltk supporting Python 3 is available at http://nltk.org/nltk3-alpha/
I suspect you will also need pyyaml and numpy installed for your python 3.
I gave this a try:
muon
check that I have installed python3-setuptools and python3-numpy
sudo pip3 install pyyaml
Having downloaded and unpacked the code from the above link
cd ~/ToolBuild/nltk-3.0a3/nltk-3.0a3
sudo python3 setup.py install
python3
Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> dir(nltk)
['AbstractLazySequence', 'AffixTagger', 'AlignedSent', 'Alignment', 'AnnotationTask', 'Assignment', 'BigramAssocMeasures', 'BigramCollocationFinder', 'BigramTagger', 'BinaryMaxentFeatureEncoding', 'BlanklineTokenizer', 'BottomUpChartParser', 'BottomUpLeftCornerChartParser', 'BottomUpProbabilisticChartParser', 'Boxer', 'BrillTagger', 'BrillTaggerTrainer', 'CfgReadingCommand', 'ChartParser', 'ChunkParserI',..........

pip install a local git repository

I can't find the correct way to install a local directory as a python package using pip.
(venv) C:\(...)>pip install . --no-index
Ignoring indexes: http://pypi.python.org/simple/
Unpacking c:\users\fsantos\desktop\biskates.com\biskates\forks\django-pipeline
Running setup.py egg_info for package from file:///(...)%5Cforks%5Cdjango-pipeline
Installing collected packages: django-pipeline
Running setup.py install for django-pipeline
Successfully installed django-pipeline
Cleaning up...
(venv) C:\(...)>cd ..
(venv) C:\(...)>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pipeline
>>> pipeline.__file__
'C:\\(...)site-packages\\pipeline\\__init__.py'
>>>
As you can see pip just copied over the package to site-packages. How can I avoid this, and use the package directly from its source folder?
I'm trying to integrate django-pipeline into my Django project, but I want to add support for Django 1.4 first, so I forked and cloned my fork.
I can also just use:
cd your-local-repo
pip install -e .
or
python setup.py install develop
If you're working in a venv, you can do this:
env/bin/pip install git+file:///path/to/your/git/repo
Or with a branch:
env/bin/pip install git+file:///path/to/your/git/repo#mybranch
You can use pip or pipenv with the following command to install from a local git repo:
pip install git+file:///path/to/your/package#egg=package-name
Note that there are 3 slashes after file: here.
To install from a remote repo use:
pip install git+ssh://git#github.com:Username/Project.git
You can also specify a desired branch like so:
pip install git+ssh://git#github.com:Username/Project.git#master
I just rounded up the previous answers and comments from Quilt and nanounanue and this question. Also posted it here.

Categories

Resources