Decide which python version to use for pip and easy_install - python-2.7

I have two python versions on my server namely 2.4 and 2.7. It is running RHEL 5.8.
I already have pip and easy_install installed on my server.
When I try to install ipython using easy_install or pip, it gives me an error which probably does not support in python 2.4.
I want to use python 2.7 for both pip and easy_install since I would want to use the latest version of the both.
What should I do to have pip and easy_install use python 2.7. Python 2.4 is installed by default by the system and I do want to keep it.
Python 2.7 is installed at another location.
Below is the traceback both for easy_install and pip. Both end up in the same error. Any kind of help is appreciated.
PIP
ronak#ronak fun $ sudo pip install ipython
Downloading/unpacking ipython
Downloading ipython-0.13.zip (6.4Mb): 6.4Mb downloaded
Running setup.py egg_info for package ipython
Traceback (most recent call last):
File "<string>", line 14, in ?
File "/usr/local/home/ronak/fun/build/ipython/setup.py", line 23
from __future__ import print_function
SyntaxError: future feature print_function is not defined
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in ?
File "/usr/local/home/ronak/fun/build/ipython/setup.py", line 23
from __future__ import print_function
SyntaxError: future feature print_function is not defined
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/ronak/.pip/pip.log
EASY_INSTALL:
ronak#ronak $ sudo easy_install ipython
Searching for ipython
Reading http://pypi.python.org/simple/ipython/
Reading http://ipython.scipy.org
Reading http://ipython.scipy.org/dist
Reading http://ipython.scipy.org/dist/0.8.4
Reading http://ipython.scipy.org/dist/0.9.1
Reading http://ipython.org
Reading http://archive.ipython.org/release/0.12.1
Reading https://github.com/ipython/ipython/downloads
Reading http://ipython.scipy.org/dist/old/0.9
Reading http://ipython.scipy.org/dist/0.10
Reading http://archive.ipython.org/release/0.11/
Reading http://archive.ipython.org/release/0.12
Best match: ipython 0.13
Downloading https://github.com/downloads/ipython/ipython/ipython-0.13.zip
Processing ipython-0.13.zip
Running ipython-0.13/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vgPLN2/ipython-0.13/egg-dist-tmp-GHUgsq
Traceback (most recent call last):
File "/usr/bin/easy_install", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1712, in main
with_ei_usage(lambda:
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
return f()
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1716, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/lib/python2.4/distutils/core.py", line 149, in setup
dist.run_commands()
File "/usr/lib/python2.4/distutils/dist.py", line 946, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.4/distutils/dist.py", line 966, in run_command
cmd_obj.run()
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 211, in run
self.easy_install(spec, not self.no_deps)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 446, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 476, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 655, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 930, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 919, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 61, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 105, in run
return func()
File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 64, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 23
from __future__ import print_function
SyntaxError: future feature print_function is not defined

One way would be:
Open pip/easy_install in text editor
Check top line, it should say
#! /usr/bin/python
Change it to #!path/to/python2.7

You should check this SO question.
You may also want to consider using virtual environment through virtualenv and virtualenvwrapper to manage which version of Python your packages should use.

If you would like to easily install iPython, SciPy, MatPlotLib, etc. by downloading a .dmg, you can try here:
http://www.enthought.com/products/epd_free.php
Or if you have a academic email address:
http://www.enthought.com/products/edudownload.php

sudo /location/to/python2.7 /path/to/pip install ipython
If you have a recent version of pip, you an also try sudo pip-2.7 install ipython

Related

Pip does not work after upgrade to ubuntu-16.10

Running a command alongwith pip gives the following error. Even the command pip -V produces the following error.
I read that the error is due to setuptools version 31.0.0 and it should be lower than 28.0.0. But the version of my setuptools is 26.1.1 and it still gives the same error.
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in
from pip import main
File "/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 26, in
from pip.utils import get_installed_distributions, get_prog
File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 27, in
from pip._vendor import pkg_resources
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in
#_call_aside
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
The only solution I could find is reinstalling pip. Run these commands on your terminal
wget https://bootstrap.pypa.io/get-pip.py
sudo -H python get-pip.py --prefix=/usr/local/
However, this works only for pip, not pip3!
Upgrade your setuptools:
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3
Generally sudo combined with pip is considered harmful, avoid this when your system is not already broken.
Please refer to https://stackoverflow.com/a/48126778/7596504. The problem could be fixed by modifying your /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py.

Python 2.6 or 2.7 setuptools > OSError - "Bootstra...sys.argv" = "setuptools failed with error code 1" > (Certbot-auto)

When trying to run "certbot-auto" for the first time instead of "letsencrypt-auto" to renew certificates on a server, it seems to fail with a couple of messages:
OSError: Command /root/.local/share/letsencrypt/bin/python2.7 -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" --always-copy -U setuptools failed with error code 1
The default Python built into my CentOS is 2.6, but I also have an ALTINSTALL setup with Python 2.7.
I cannot make Python 2.7 my default distribution, as this then breaks YUM, and certbot-auto is not able to access "the EPEL repository needed" if YUM is not available.
I am not able to renew my certificates with Let's Encrypt, please, any and all help is greatly appreciated.
I ran this command:
./certbot-auto --verbose
It produced this output (with --verbose turned on):
Bootstrapping dependencies for RedHat-based OSes...
yum is /usr/bin/yum
To use Certbot, packages from the EPEL repository need to be installed.
Loaded plugins: security
Setting up Install Process
Package matching epel-release-6-7.noarch already installed. Checking for update.
Nothing to do
Loaded plugins: security
Setting up Install Process
Package gcc-4.4.6-3.el6.x86_64 already installed and latest version
Package dialog-1.1-9.20080819.1.el6.x86_64 already installed and latest version
Package augeas-libs-0.9.0-1.el6.x86_64 already installed and latest version
Package openssl-1.0.0-20.el6_2.5.x86_64 already installed and latest version
Package openssl-devel-1.0.0-20.el6_2.5.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Package redhat-rpm-config-9.0.3-34.el6.noarch already installed and latest version
Package ca-certificates-2010.63-3.el6_1.5.noarch already installed and latest version
Package python-2.6.6-29.el6_2.2.x86_64 already installed and latest version
Package python-devel-2.6.6-29.el6_2.2.x86_64 already installed and latest version
Package python-virtualenv-1.7-1.el6.noarch already installed and latest version
Package python-tools-2.6.6-29.el6_2.2.x86_64 already installed and latest version
Package python-pip-0.8-1.el6.noarch already installed and latest version
Package 1:mod_ssl-2.2.15-15.el6.centos.1.x86_64 already installed and latest version
Nothing to do
Creating virtual environment...
Running virtualenv with interpreter /usr/local/bin/python2.7
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in /root/.local/share/letsencrypt/bin/python2.7
Also creating executable in /root/.local/share/letsencrypt/bin/python
Installing setuptools..........................................
Complete output from command /root/.local/share/letsencrypt/bin/python2.7 -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" --always-copy -U setuptools:
Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Searching for setuptools
Reading http://pypi.python.org/simple/setuptools/
Best match: setuptools 32.3.0
Downloading https://pypi.python.org/packages/b0/04/d7aac18d0d8b1b9bd9b88af02af8090e72653753bced3226f9903cabb991/setuptools-32.3.0.zip#md5=f72378b7152ad33d8a33a44d673f5794
Processing setuptools-32.3.0.zip
Running setuptools-32.3.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hYCpVy/setuptools-32.3.0/egg-dist-tmp-0d8jk4
/usr/local/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'src_root'
warnings.warn(msg)
Traceback (most recent call last):
File "<string>", line 279, in <module>
File "<string>", line 214, in main
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in main
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1716, in <lambda>
File "/usr/local/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 211, in run
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 446, in easy_install
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 476, in install_item
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 655, in install_eggs
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 930, in build_and_install
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 919, in run_setup
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 62, in run_setup
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 105, in run
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 64, in <lambda>
File "setup.py", line 181, in <module>
File "/usr/local/lib/python2.7/distutils/core.py", line 111, in setup
_setup_distribution = dist = klass(attrs)
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/dist.py", line 264, in __init__
File "/usr/local/lib/python2.7/distutils/dist.py", line 287, in __init__
self.finalize_options()
File "/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/dist.py", line 297, in finalize_options
File "/usr/bin/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1959, in load
ImportError: <module 'setuptools.dist' from '/usr/bin/setuptools-0.6c11-py2.7.egg/setuptools/dist.py'> has no 'check_specifier' attribute
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 2098, in <module>
main()
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 1040, in create_environment
search_dirs=search_dirs, never_download=never_download)
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 593, in install_setuptools
search_dirs=search_dirs, never_download=never_download)
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 567, in _install_req
cwd=cwd)
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 1006, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /root/.local/share/letsencrypt/bin/python2.7 -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" --always-copy -U setuptools failed with error code 1
My operating system is (include version):
CentOS 6.2
Python 2.6 (needed for YUM)
Python 2.7 as "altinstall"
Apache/2.2.15
Setting Python 2.7 as default yields the following for YUM commands:
("no module named yum")

No module named virtualenvwrapper

I have Django 1.9.7 installed, and its works fine, but every time I open the terminal, I get this message.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
When I startproject in Django, it works fine. I wonder whether this will cause problems in the future, and how can I fix it?
I speculate that it is causing this problem because I used to use Python 2.7 with Django 1.9.7. I have recently upgrade by python to 2.4, but it seems that my packages for python 2.7 still exist in my computer. However, when I tried removing the python 2.7 packages with pip uninstall python == 2.7, I get this error
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/uninstall.py", line 76, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 336, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 742, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/f7/jrgwm7ms037f4v9lydh4cjcr0000gn/T/pip-dSXtam-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/Python-2.7.10-py2.7.egg-info'
I have read that it is not good to uninstall packages using pip because it does uninstall everything, but I am not sure how else to do it, and I am not sure how to fix the module issue either.

python3.2 + virtualenv - env create failed

I've got a py2.7 project which I want to test under py3.2. For this purpose, I want to use virtualenv. I wanted to create an environment that would run 3.2 version internally:
virtualenv 3.2 -p /usr/bin/python3.2
but it failed. My default python version is 2.7 (ubuntu default settings). Here is virtualenv --version 1.10. The error output is:
Running virtualenv with interpreter /usr/bin/python3.2
New python executable in 3.2/bin/python3.2
Also creating executable in 3.2/bin/python
Installing Setuptools...................................................................................................................................................................................................................................done.
Installing Pip..............
Complete output from command /home/tomasz/Develop...on/3.2/bin/python3.2 setup.py install --single-version-externally-managed --record record:
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, find_packages
File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/usr/lib/python2.7/dist-packages/setuptools/extension.py", line 2, in <module>
from setuptools.dist import _get_unpatched
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
----------------------------------------
...Installing Pip...done.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2308, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 821, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 963, in create_environment
install_sdist('Pip', 'pip-*.tar.gz', py_executable, search_dirs)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 932, in install_sdist
filter_stdout=filter_install_output)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 899, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/tomasz/Develop...on/3.2/bin/python3.2 setup.py install --single-version-externally-managed --record record failed with error code 1
I don't know what the hell is this syntax error - where does it come from... I know there was a change in try...catch statement syntax between 2.x and 3.x, but should virtualenv throw syntax errors?
I'd be grateful if someone pointed me out if there's something I'm doing wrong or if there is an installation problem on my machine.
To create a Python 3.2 virtual environment you should use the virtualenv you installed for Python 3.2. In your case that would be:
/usr/bin/virtualenv-3.2
You'll have to use a Python 3 version of virtualenv; the version you are using is installing Python 2 tools into a Python 3 virtual environment and these are not compatible.
virtualenv --python=/usr/bin/python3.2 --no-site-packages ENV

Problems running Cython

I'm trying to run cython with Python2.7 installed using OSX running Mountain Lion but I get the following errors:
Traceback (most recent call last):
File "/usr/local/bin/cython", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: Cython==0.17
How can I fix this?
Thanks!
Probably what happened is that you installed cython with one version of python and are trying to run it with another. Rather than doing the standard
python setup.py build
sudo python setup.py install
Try just switching to root and both building and installing using an explicit version of python:
sudo su
/usr/bin/python setup.py build
/usr/bin/python setup.py install
(Note that this all assumes that you're installing from a source tarball).