Python3.4.1 LINUX - from pip import main raises ImportError: Cannot import name 'main' - pip

I'm using a server for which I am not root, and I have several scripts requiring Python 3.4.1. I built the software from the source tarball using the following syntax
$ ./configure --prefix=$HOME
$ make
$ make install
The software installed successfully, as I was able to launch python3 after modifying my .bash_profile to look in $HOME/bin. However, Pip was not so lucky.
$ pip3.4
Traceback (most recent call last):
File "/home/scnorton/bin/pip3.4", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
When I tried to run python3 get-pip.py, I get the following error:
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
I have checked the /usr/lib64 directory and concluded that zlib is installed on the server. I even executed the command module load zlib-1.2.8-1 and tried reinstalling pip again, with no luck. Could the problem be that Python3.4.1 is installed as a 32-bit application? If so, where can I go to get 64-bit Python3.4.1 for Linux?

Related

How to debug pip install <package name>

If I want to debug the setup.py file of my package packagename getting installed via "pip install packagename" , is there a way to do so? I have tried downloading the source, adding set_trace() in setup.py and run:
pip install .
However, as soon I get pdb() prompt, the install fails with error:
processing /Users/skauser/python-ibmdb/IBM_DB/ibm_db
Complete output from command python setup.py egg_info:
> /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py(31)<module>()
-> machine_bits = 8 * struct.calcsize("P")
(Pdb)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/Library/anaconda3/lib/python3.7/bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "/Library/anaconda3/lib/python3.7/bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/
Although I can debug the source via: python setup.py build, the behavior that I want to debug is applicable when installed through pip.
Pip is a python program. You can see it's content with cat $(which pip). Then you can copy it to a new file in your project's directory. For example, here is how it looks like for me:
File mypip.py:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Then you can add a breakpoint with pdb or use PyCharm as mentioned in the answer from Igor Yudnikov.
For reference, this is how it to looks like in my Pycharm
Oh! Just found a solution, its pretty easy. What is pip? It's a plain python file, which is I think somehow bound to run via python, and under the hood system makes something like
python pip install ...
so, at first we need to know where is pip
which pip
says
/Users/me/PycharmProjects/etlscripts/venv/bin/pip
So, we may go to Pycharm, create config like
then you'll be able to catch your exception. Cheers.

Problem installing importlib on Mac with pip3

Good morning!
Until yesterday I was using python 2.7 and using the following code for writing output files for my scripts:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
But now I'm upgrading my code to python 3.7, so now I need to use importlib.reloadinstead of just reload. However, typing sudo -H pip3 install importlib on my shell gives me the following error:
Collecting importlib
Using cached https://files.pythonhosted.org/packages/31/77/3781f65cafe55480b56914def99022a5d2965a4bb269655c89ef2f1de3cd/importlib-1.0.4.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 6, in <module>
import distutils.core
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 16, in <module>
from distutils.dist import Distribution
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 19, in <module>
from distutils.util import check_environ, strtobool, rfc822_escape
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/util.py", line 9, in <module>
import importlib.util
ModuleNotFoundError: No module named 'importlib.util'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-3cz_3d6n/importlib/
After looking for solutions I also tried to upgrade setuptools, but that didn't fix my problem.
Many thanks in advance!
importlib at PyPI is an outdated package intended for very old Python versions. For new versions of Python importlib is a module from the standard library, you don't need to install it, it's always available.

Cannot install enum package on Python3.6

I am trying to run this example on MacOS High Sierra. It requires installing the page package, which requires installing the pytodos package, which requires installing the enum package, installation of which fails.
$ python3 page_object_test_case.py
Traceback (most recent call last):
File "page_object_test_case.py", line 3, in <module>
import page
ModuleNotFoundError: No module named 'page'
$ pip3 install page
...
Successfully installed click-6.7 page-1.0.16
$ python3 page_object_test_case.py
Traceback (most recent call last):
File "page_object_test_case.py", line 3, in <module>
import page
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/page/__init__.py", line 2, in <module>
from pytodos import todo
ModuleNotFoundError: No module named 'pytodos'
$ pip3 install pytodos
Collecting pytodos
...
Collecting enum==0.4.6 (from pytodos)
Downloading https://files.pythonhosted.org/packages/0c/4e/1ea357e7783c756bb579333c1e4a026fb331371ee771f616ffedc781e531/enum-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/version.py:1: UserWarning: Module enum was already imported from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/enum.py, but /private/var/folders/h3/1znktv0s36j1fdqcdrr0zvcw0000gn/T/pip-install-jhfn7vc3/enum is being added to sys.path
import pkg_resources
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/h3/1znktv0s36j1fdqcdrr0zvcw0000gn/T/pip-install-jhfn7vc3/enum/setup.py", line 24, in <module>
version = main_module.__version__
AttributeError: module 'enum' has no attribute '__version__'
Note that I've tried to do the same on Ubuntu. And I had to repeat every step. However, installation of enum failed with this error instead:
AttributeError: module 'enum' has no attribute 'IntFlag'
What am I doing wrong?
You went wrong at pip install page.
You were supposed to provide your own module page.py, as described here.
pip install page pulled in some garbage and unrelated/unmaintained projects from PyPI.

Install dbf- no module named enum

I am trying to install the dbf module- see below link.
https://pypi.python.org/pypi/dbf
When I install the module in the Command Prompt, I receive the following invalid syntax error:
C:\Users\dbf-0.96.005>python setup.py install
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running install
running build
running build_py
running install_lib
byte-compiling C:\Python27\Lib\site-packages\dbf\ver_33.py to ver_33.pyc
File "C:\Python27\Lib\site-packages\dbf\ver_33.py", line 2577 raise DbfError<"unable to write updates to disk, original data restored: %r"X<exc,>> from None
^
SyntaxError: invalid syntax
running install_egg_info
Removing C:\Python27\Lib\site-packages\dbf-0.96.005-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\dbf-0.96.005-py2.7.egg-info
C:\Users\dbf-0.96.005>
Then, if I try to import dbf in Interpreter, I get:
Traceback (most recent call last):
File "W:/Engineering/ENGINEER/LAMP (062012)/Database/VisualDatabase/test", line 1, in <module>
import dbf
File "C:\Python27\ArcGIS10.3\lib\site-packages\dbf\__init__.py", line 11, in <module>
from dbf import ver_2 as _dbf
File "C:\Python27\ArcGIS10.3\lib\site-packages\dbf\ver_2.py", line 49, in <module>
from enum import Enum, IntEnum
ImportError: No module named enum
>>>
Do I need to install Enum? Is there a version of Enum I need?
Sorry, I must have foobarred the last package I created.
Do a
pip install enum34
first.

HTTPLIB2 Error installing python-twitter on mac osx

Hello I am trying to install python-twitter and one of the dependencies HTTPLIB2 is giving me a lot of problems. I have searched the internet up and down but maybe I do not know what the right key words are. Here is the problem.
I am installing python-twitter. I install the requirements either by "pip install -r requirements.txt" or doing them one by one through for example "pip install httplib2". Then I run "python setup.py install". It's happy but then "python setup.py test" fails as followed with an error on import HTTPLIB2.
python setup.py test
running test
running egg_info
writing requirements to python_twitter.egg-info/requires.txt
writing python_twitter.egg-info/PKG-INFO
writing top-level names to python_twitter.egg-info/top_level.txt
writing dependency_links to python_twitter.egg-info/dependency_links.txt
reading manifest file 'python_twitter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '.DS_Store'
writing manifest file 'python_twitter.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 73, in <module>
Main()
File "setup.py", line 66, in Main
setuptools.setup(**METADATA)
File
....
<deleted these parts to save space>
module = __import__('.'.join(parts_copy))
File "/Users/ME/Downloads/python-twitter-1.0/twitter_test.py", line 30, in <module>
import twitter
File "/Users/ME/Downloads/python-twitter-1.0/twitter.py", line 65, in <module>
import oauth2 as oauth
File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 32, in <module>
import httplib2
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 347
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
But I thought the print error was an incompatibility between python 2 and 3. Why am I getting this while I clearly have python 2.7 (I checked and uninstalled and reinstalled HTTPLIB2).
Thanks much for your help
i had a same issue. It seems to be python2.7 and 3.x version conflict issue and resolved by
python2.7 -m pip install -t lib/ -r requirements.txt
Just in case, this happens when you install httplib2 with a python3 version of pip and then execute it with python2.
This happens for example when creating manually an environment with:
pip install -t lib/ -r requirements
As it happens when creating an AppEngine standard environment vendor folder.
This happens because contrary to most of the libraries, httplib2 has completely different versions for python2 and python3.

Resources