Error in running a python script-In pip installation - python

I am running a python script where it is setting up an environment in unix to run other python scripts. It is trying to install pip and it fails with the following error.
2016-01-25 12:05:50,291 - Checking if pip is installed.
2016-01-25 12:05:50,291 - Pip is not currently installed.
2016-01-25 12:05:50,291 - Installing pip.
Traceback (most recent call last):
File "/tmp/tmpoDUDVr.py", line 19017, in <module>
main()
File "/tmp/tmpoDUDVr.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "/tmp/tmpoDUDVr.py", line 82, in bootstrap
import pip
File "/tmp/tmpm4FmfJ/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/vcs/subversion.py", line 9, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/index.py", line 29, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/wheel.py", line 39, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/scripts.py", line 14, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
Failed to install pip. Error was Command '['python', '/tmp/tmpoDUDVr.py', '- -user', '--upgrade', '--force-reinstall']' returned non-zero exit status 1
I have already installed pip using the command yum -y install python-pip but still it throws this error. I am not able to find this tmp/tmpoDUDVr.py file and everytime I run this tmp file varies.I tried searching hidden files too(ls -a) Could you please shed light? Any thoughts much appreciated..

Try to use "sudo" in this case. PIP was installed the first time as root...

Related

How tp get pip to run in in Xubuntu

I've installed python 3.9 on Xubuntu 20.04 using apt. When I try to run pip, I get the error, No module named 'distutils.cmd'
For example, python3.9 -m pip --help gives the traceback
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/saul/.local/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/configuration.py", line 26, in <module>
from pip._internal.utils.logging import getLogger
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 27, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 39, in <module>
from pip._internal.locations import get_major_minor_version
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 14, in <module>
from . import _distutils, _sysconfig
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
Where can I find distutils.cmd and where should I put it? I'm not at all knowledgeable about linux, just a naive user.
I found this post which indicated that there isn't a separate distutils module for python3.9, and seemed to suggest using virtual environments. When I tried
python3.9 -m venv /home/saul/.venvs/py39
however, I got the message
Error: Command '['/home/saul/.venvs/py39/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py (probably will give an error, I tried and it gave an error for me)
sudo apt install python3.9-distutils
python3.9 get-pip.py (can skip and directly check the version, if it works then good otherwise run this command and then check version. I ran this command before checking version)
And finally,
python3.9 -m pip -V (should give console as pip 22.x.x from some-path (python3.9) )
I ran these commands, it worked for me. Hope it helps you too.
I stumbled on this, which worked:
sudo apt install python3.9-venv

msys2/mingw64: pip: VC 6.0 is not supported by this module

I try to install a package in Windows 10 (mingw64) and get this error:
IEUser#MSEDGEWIN10 MINGW64 /c/Users/IEUser/PycharmProjects/myapp_msi-msys/myapp_msi
$ pip install -e git+https://source.example.lan:40443/repos/myapp_common#egg=myapp_common
Obtaining myapp_common from git+https://source.example.lan:40443/repos/myapp_common#egg=myapp_common
Cloning https://source.example.lan:40443/repos/myapp_common to c:/users/ieuser/pycharmprojects/myapp_msi-msys/myapp_msi/src/myapp-common
Username for 'https://source.example.lan:40443':
Password for 'https://tguettler#source.example.lan:40443':
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:/msys64/mingw64/lib/python2.7/site-packages/setuptools/__init__.py", line 191, in <module>
monkey.patch_all()
File "C:/msys64/mingw64/lib/python2.7/site-packages/setuptools/monkey.py", line 101, in patch_all
patch_for_msvc_specialized_compiler()
File "C:/msys64/mingw64/lib/python2.7/site-packages/setuptools/monkey.py", line 164, in patch_for_msvc_specialized_compiler
patch_func(*msvc9('find_vcvarsall'))
File "C:/msys64/mingw64/lib/python2.7/site-packages/setuptools/monkey.py", line 151, in patch_params
mod = import_module(mod_name)
File "C:/msys64/mingw64/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "C:/msys64/mingw64/lib/python2.7/distutils/msvc9compiler.py", line 306, in <module>
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
distutils.errors.DistutilsPlatformError: VC 6.0 is not supported by this module
What can I do to fix this?
I was following these instructions to set up my development environment: https://www.gtk.org/download/windows.php
Update
Just for the records, I switched from gtk to qt (PySide2) and now I can use the default Python for windows. Everything is much easier now.
In MSYS2, many of the issues are patched downstream with the MINGW-packages that go in to the pacman repository. In this case, the reason you are getting this error is that you have setuptools pip installed, instead of installed using the pacman repository. To fix this issue:
pip uninstall setuptools
pacman -S mingw-w64-x86_64-python-setuptools
or if you are using modern Python:
pip3 uninstall setuptools
pacman -S mingw-w64-x86_x64-python3-setuptools

undefined symbol: __intel_sse2_strcpy

I am trying to install phonopy on our super computer's login node following the instruction on under the Building using setup.py section here https://atztogo.github.io/phonopy/install.html.
Basically, just two commands:
tar xvfz phonopy-1.11.2.tar.gz
python setup.py install --user
It installs with no problem; however, when I use it, I get the following errors saying undefined symbol: __intel_sse2_strcpy. Here is the complete error message:
/home/syuan43/.local/bin/bandplot
Traceback (most recent call last):
File "/home/syuan43/.local/bin/bandplot", line 4, in <module>
__import__('pkg_resources').run_script('phonopy==1.11.8.5', 'bandplot')
File "/software/CentOS-6/tools/python-2.7.9/lib/python2.7/site-packages/pkg_resources/__init__.py", line 726, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/software/CentOS-6/tools/python-2.7.9/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1491, in run_script
exec(script_code, namespace, namespace)
File "/home/syuan43/.local/lib/python2.7/site-packages/phonopy-1.11.8.5-py2.7-linux-x86_64.egg/EGG-INFO/scripts/bandplot", line 52, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/__init__.py", line 37, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/api_phonopy.py", line 39, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/structure/symmetry.py", line 37, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/structure/spglib.py", line 35, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/_spglib.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/phonopy/_spglib.py", line 6, in __bootstrap__
ImportError: /home/syuan43/.python-eggs/phonopy-1.11.8.5-py2.7-linux-x86_64.egg-tmp/phonopy/_spglib.so: undefined symbol: __intel_sse2_strcpy
Not sure if this may help, here is the module that I am using:
$ module list
Currently Loaded Modules:
1) ifort_icc/15.0 2) intel_mpi/5.0.1 3) python/2.7.9
Any idea how to resolve the problem above? Or any suggestions what might be the cause of it?
(Old issue but I'll add an answer for the next me.)
For me it was a compiler issue. Doing:
export CC=gcc
before doing the pip installs fixed this for me.
See also: https://github.com/jswhit/pyproj/issues/76
In my case uninstalling cf_units and installing again worked. I uninstalled cf_units from PIP and installed using anaconda
pip uninstall cf_units
conda install -c conda-forge cf_units

Attribute Error Installing with pip

This is a head stumper so I am posting this question AFTER having examined and read all of the prior posts on this issue.
Running OSX 10.9 Python 2.7 no virtualenv
pip install awssh
Downloading/unpacking awssh
Downloading awssh-0.1.tar.gz
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.2-py2.7.egg/pip/basecommand.py",
line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.2-py2.7.egg/pip/commands/install.py",
line 274, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/Library/Python/2.7/site-packages/pip-1.5.2-py2.7.egg/pip/req.py",
line 1215, in prepare_files
req_to_install.run_egg_info()
File "/Library/Python/2.7/site-packages/pip-1.5.2-py2.7.egg/pip/req.py",
line 288, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "/Library/Python/2.7/site-packages/pip-1.5.2-py2.7.egg/pip/req.py",
line 265, in setup_py
import setuptools
File "/Library/Python/2.7/site-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extension import Extension
File "/Library/Python/2.7/site-packages/setuptools/extension.py", line 8, in <module>
File "/Library/Python/2.7/site-packages/setuptools/dist.py", line 21, in <module>
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'
This error is caused by the presence of an outdated version of pkg_resources. In order to get rid of the error, do the following:
Start a python session, import pkg_resources, and view the file from which it is loaded:
In [1]: import pkg_resources
In [2]: pkg_resources.__file__
Out[2]: '/usr/lib/python2.7/dist-packages/pkg_resources.pyc'
Remove this file (and the associated *.py file):
$ sudo rm /usr/lib/python2.7/dist-packages/pkg_resources.py*
That's it! Re-run the installation; it should complete without any errors:
$ sudo pip install awssh
Warning
If you're on a Debian based Linux system, this file might have been installed via the python-pkg-resources package. Therefore updating or reinstalling this package will reinstate the stale module! Also be aware that you're messing with a file which is supposed to be controlled by apt.

ImportError while installing pip in virtualenv

I have a rhel machine with python2.6 installed on it. I've been trying to have an alternate install of python2.7 and set up a virtualenv for using 2.7. I installed python2.7 by building from source as follows:
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
I already had virtualenv installed on the system so I used it to create a venv for 2.7 as follows:
virtualenv -p python2.7 --no-setuptools py27
. py27/bin/activate
Now when I try to install pip inside the venv, it fails like so:
python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19857, in <module>
main()
File "get-pip.py", line 151, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 81, in bootstrap
import pip
File "/tmp/tmpArPs31/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/download.py", line 29, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
Can't figure out what's going wrong here. Please help.
I've installed python 2.7.8.
EDIT: I initially tried creating virtualenv without --no-setuptools option but that gave me the same error:
virtualenv -p python2.7 py27_with_pip
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in py27_with_pip/bin/python2.7
Also creating executable in py27_with_pip/bin/python
Installing setuptools, pip...
Complete output from command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0- py2.py3-none-any.whl/pip/__init__.py", line 15, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/vcs/mercurial.py", line 11, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/download.py", line 29, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 2363, in <module>
main()
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 848, in main
symlink=options.symlink)
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 1016, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 984, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 926, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
I tried installing pip with python2.7 directly but even that doesn't work:
python2.7 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19857, in <module>
main()
File "get-pip.py", line 151, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 81, in bootstrap
import pip
File "/tmp/tmpPSVEkk/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/download.py", line 29, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
I was in a situation similar to yours, and I eventually found the fix. At least in my case the root problem was that when I compiled python 2.7.8 the build process didn't find the proper OpenSSL libraries (because they were not installed on my system). After make finished running it showed a summary similar to this:
Failed to find the necessary bits to build these modules:
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
This doesn't prevent make install from working, and after that Python works just fine, except that it can't access https URLs and other related functionality. You can tell if this is your case by starting python and then typing
import ssl
If you see an ImportError, then the ssl module is missing. Otherwise, you see no message at all.
I fixed this by installing the OpenSSL libraries by running (as root):
yum install openssl-devel
After this was in place, I rebuilt Python with make (now _ssl was not listed as missing), followed by make install. After this, running get-pip.py worked without a hitch.
Hope this helps!

Categories