NameError: name 'install' is not defined when installing packages using pip - python

I am trying to create virtualenv and install project dependencies using pip.
$ mkvirtualenv --no-site-packages --distribute myenv
(myenv)$ pip install -r requirements.txt
I also set up export VIRTUALENV_DISTRIBUTE=true in ~/.bash_profile
After installing some packages pip shows following error:
.....
Could not find the /Users/me/.virtualenvs/myenv/lib/python2.7/site-packages/site.py element of the Setuptools distribution
Patched done.
Relaunching...
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'install' is not defined
----------------------------------------
Cleaning up...
Command /Users/me/.virtualenvs/myenv/bin/python -c "import setuptools;__file__='/Users/me/.virtualenvs/myenv/build/distribute/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/r0/2b441j6x5rq8y964bhd15gkm0000gn/T/pip-wyn1Ys-record/install-record.txt --single-version-externally-managed --install-headers /Users/me/.virtualenvs/myenv/include/site/python2.7 failed with error code 1 in /Users/me/.virtualenvs/myenv/build/distribute
Exactly the same happens without --distribute switch and without export VIRTUALENV_DISTRIBUTE=true
Here is my requirements.txt file:
Django==1.5
Pillow==1.7.6
South==0.7.3
amqplib==1.0.2
anyjson==0.3.1
celery==2.5.3
distribute==0.6.10
django-celery==2.4.2
django-indexer==0.3.0
django-kombu==0.9.4
django-mptt==0.5.2
django-paging==0.2.4
django-picklefield==0.2.1
django-social-auth==0.7.22
django-tagging==0.3.1
django-taggit==0.9.3
django-templated-email==0.4.7
django-templatetag-sugar==0.1
eventlet==0.9.16
greatape==0.3.0
greenlet==0.3.4
html5lib==0.90
httplib2==0.8
kombu==2.1.7
lockfile==0.9.1
oauth2==1.5.211
pycrypto==2.3
python-daemon==1.6
python-dateutil==1.5
python-openid==2.2.5
raven==1.0.4
sentry==2.0.0-RC6
simplejson==2.3.2
ssh==1.7.8
wsgiref==0.1.2
I am using Mac OS X 10.9.2.
I don't want to change anything in requirements.txt I just want to install all dependencies and run this project.

Remove the distribute package from the list, recreate your environment and reinstall the requirements.
You may remove the wsgiref as well (although not much important).

Related

No such file or directory error when installing github package in anaconda

I am trying to install this module from github.
https://github.com/ChristianSchneeweiss/Chat-txt-to-csv
First, I am following the steps listed here.
https://medium.com/i-want-to-be-the-very-best/installing-packages-from-github-with-conda-commands-ebf10de396f4
so I used this line in Anaconda Powershell Prompt
pip install git+git://github.com/ChristianSchneeweiss/Chat-txt-to-csv.git
it didn't work. and then I used this code, based on the suggestions here.
Use package from Github in Conda Virtual Environment
pip install C:\Users\Lulz\Documents\mamanitip\chat_wa\Chat-txt-to-csv-master.zip
it didn't work either. both codes resulted in this error.
command: 'C:\ProgramData\Anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Lulz\\AppData\\Local\\Temp\\pip-req-build-2cr6dd41\\setup.py'"'"'; __file__='"'"'C:\\Users\\Lulz\\AppData\\Local\\Temp\\pip-req-build-2cr6dd41\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Lulz\AppData\Local\Temp\pip-pip-egg-info-3o0zsjkm'
cwd: C:\Users\Lulz\AppData\Local\Temp\pip-req-build-2cr6dd41\
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\tokenize.py", line 447, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Lulz\\AppData\\Local\\Temp\\pip-req-build-2cr6dd41\\setup.py'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
i've tried creating new Microsoft accounts, and installing in a new environment, but it still didn't work. it always resulted in the same error, just different users (as I change Microsoft accounts). what did I do wrong? thank you so much for your help.
The package at https://github.com/ChristianSchneeweiss/Chat-txt-to-csv cannot be installed with pip because it does not have the file setup.py. What you can do instead is to download the project onto your computer, install the project's dependencies, and then use the project from its directory. If you run python from within that project's directory, it will find the package.
git clone https://github.com/ChristianSchneeweiss/Chat-txt-to-csv
cd Chat-txt-to-csv
python -m pip install --no-cache-dir -r requirements.txt
python convert.py chat.txt

problems when using pip install

I am not quite experienced using pip. When I tried to install some packages, I had this error and had no idea what that meant. This happened to multiple packages that I tried to install. Any suggestions would be appreciated.
sudo pip install mysql-python
Password:
WARNING: The directory '/Users/yzr/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysql-python
Downloading MySQL-python-1.2.5.zip (108 kB)
|████████████████████████████████| 108 kB 2.2 MB/s
ERROR: Command errored out with exit status 1:
command: /Users/yzr/opt/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-0kcqh5vw/mysql-python/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-0kcqh5vw/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/tmp/pip-install-0kcqh5vw/mysql-python/pip-egg-info
cwd: /private/tmp/pip-install-0kcqh5vw/mysql-python/
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-install-0kcqh5vw/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/tmp/pip-install-0kcqh5vw/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
I’m assuming you are using an Unix system such as Linux or MacOS.
Maybe you are accidentally using the python2.7 version installed on your system.
You can use a specific version of python for pip with:
python3 -m pip install mysql-python
Let me explain myself, every MacOS or Linux system has two Python versions (2.7 and 3.x) by default, and both of those versions has a pip module related to it, in other words, you have a pip module for Python 2.7 and other pip module for Python 3.x.
However, I’m assuming you are using python3 for your project, therefore, you must specify the pip module to use.
Other way to avoid this problem is using a virtual environment manager, such as pipenv or built in virtualenv module.
It looks like your pip package doesn't have the module "ConfigParser" installed. You should be able to install it by running:
pip install ConfigParser
Alternatively, depending on your Python version, try installing mysqlclient instead:
pip install mysqlclient

pip install produces the following error on mac: error: command 'gcc' failed with exit status 1

So I tried to install a package from PyPI with the following command:
sudo pip3 install switcheo
But it fails to install the package in the end.
Error checking for conflicts.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2584, in version
return self._version
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2691, in __getattr__
raise AttributeError(attr)
AttributeError: _version
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 503, in _warn_about_conflicts
package_set, _dep_info = check_install_conflicts(to_install)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 108, in check_install_conflicts
package_set, _ = create_package_set_from_installed()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 47, in create_package_set_from_installed
package_set[name] = PackageDetails(dist.version, dist.requires())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2589, in version
raise ValueError(tmpl % self.PKG_INFO, self)
ValueError: ("Missing 'Version:' header and/or METADATA file", Unknown [unknown version] (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages))
Installing collected packages: scrypt, neocore, switcheo
scrypt-1.2.1/libcperciva/crypto/crypto_aes.c:6:10: fatal error: 'openssl/aes.h' file not found
#include <openssl/aes.h>
^~~~~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-b6w97vc0/scrypt/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-qvammwag/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-b6w97vc0/scrypt/
This is the full output in the terminal after running the pip install line.
I found some solutions for linux, but there are not a lot of posts here for mac users.
I dealt with this problem for a while while trying to install another library that relies on openssl in a MacOS virtual env.
Mac has deprecated openssl in favor of their own SSL. So what you need to do is:
brew install openssl
or if it is already installed,
brew reinstall openssl
Now you need to to change the LD and CPP Flags. Refer to the openssl reinstall dialog. Should tell you where the commands!
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
For pkg-config to find openssl you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
You're either missing the OpenSSL package, or your system can't find where it is on your system. Try brew install openssl.
A more detailed answer openssl/aes.h' file not found on Mac
after spending hours, i successfullly installed.
If you are using mac and if you are using anaconda
please open python terminal from anaconda
then paste the following link and click enter.
conda install -c conda-forge/label/gcc7 wordcloud
if you need more clarity please visit following link
https://anaconda.org/conda-forge/wordcloud

`pip install -t` doesn't work with namespace packages

When I install a package with pip install -t some_dir, I can usually then add some_dir to my PYTHONPATH when running python and import the package. Like this:
~/dev/scratch [venv] » pip install -t some_dir pytest
...
Successfully installed py pytest
~/dev/scratch [venv] » PYTHONPATH=some_dir python
...
>>> import pytest
>>>
However, I recently added the library "stompest" to my dependencies, which is apparently a "namespace package" (not entirely sure what that means). It doesn't seem to work with this same pattern:
~/dev/scratch [venv] » pip install -t some_dir stompest
...
Successfully installed stompest
~/dev/scratch [venv] » PYTHONPATH=some_dir python
...
>>> import stompest.config
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named stompest.config
It works fine if I just install stompest normally (into a virtual environment, say):
~/dev/scratch [venv] » pip install stompest
...
Successfully installed stompest-2.1.6
~/dev/scratch [venv] » python
...
>>> import stompest.config
>>>
The problem seems to be that pip(?) lays down a .pth file that expects to be in the site-dir (notice f_locals['sitedir'] below):
~/dev/scratch [venv] » cat some_dir/stompest-2.1.6-py2.7-nspkg.pth
import sys,types,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('stompest',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('stompest',types.ModuleType('stompest')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
I tried also setting PYTHONUSERBASE=some_dir, but that didn't seem to make any difference. It seems like a similar issue to this one, which suggests using --egg as a workaround. I can't get --egg to work with -t, though, because I get an error that I am "attempting to install a package to a directory that is not on PYTHONPATH and which Python does not read ".pth" files from." The problem is that I can't add the directory to PYTHONPATH because it seems to be trying to install to a temporary directory:
~/dev/scratch [venv] » PYTHONPATH=some_dir pip install -t some_dir --egg stompest
Collecting stompest
Using cached stompest-2.1.6.tar.gz
Installing collected packages: stompest
Running setup.py install for stompest
Complete output from command /home/nalderso/dev/scratch/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-Wc3oaO/stompest/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fZlXM2-record/install-record.txt --compile --install-headers /home/nalderso/dev/scratch/venv/include/site/python2.7/stompest --home=/tmp/tmpHNVOP0:
running install
Checking .pth file support in /tmp/tmpHNVOP0/lib/python/
/home/nalderso/dev/scratch/venv/bin/python -E -c pass
TEST FAILED: /tmp/tmpHNVOP0/lib/python/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/tmp/tmpHNVOP0/lib/python/
and your PYTHONPATH environment variable currently contains:
'some_dir'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
----------------------------------------
Command "/home/nalderso/dev/scratch/venv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-Wc3oaO/stompest/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fZlXM2-record/install-record.txt --compile --install-headers /home/nalderso/dev/scratch/venv/include/site/python2.7/stompest --home=/tmp/tmpHNVOP0" failed with error code 1 in /tmp/pip-build-Wc3oaO/stompest
Am I doing something wrong, or is this an issue with pip?
It works when you do this:
import site
site.addsitedir('some_dir')
See https://docs.python.org/2/library/site.html#site.addsitedir
I found this answer in a post by Matt Iversen (Ivoz) in this pip issue. Note that talk in this issue continues about some corner cases you might run into.

Pandas Install Issue

I've run pip install pandas and seemed to get a ton of warnings but by the end everything seemed to have installed successfully. I've also run pip install requests.
When I call a function with this line:
getTeamRoster("http://modules.ussquash.com/ssm/pages/leagues/Team_Information.asp?id=11325")
I get this error (seems not to like the read_html call and wants me to install lxml?):
Traceback (most recent call last):
File "SquashScraper.py", line 51, in <module>
main()
File "SquashScraper.py", line 48, in main
getTeamRoster("http://modules.ussquash.com/ssm/pages/leagues/Team_Information.asp?id=11325")
File "SquashScraper.py", line 39, in getTeamRoster
tables = pd.read_html(requests.get(teamURL).content)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas/io/html.py", line 865, in read_html
parse_dates, tupleize_cols, thousands, attrs, encoding)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas/io/html.py", line 718, in _parse
parser = _parser_dispatch(flav)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas/io/html.py", line 677, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it
Any ideas what's going on here?
Happy to provide more info if needed.
Thanks,
bclayman
Edit to add:
pip install got me:
error: command '/usr/bin/clang' failed with exit status 1 Command /usr/local/bin/python3 -c "import setuptools, tokenize;__file__='/private/var/folders/m_/v2nkdbd935l6zwky8jm1g68r0000gn/T/pip_bu‌​ild_ben/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/m_/v2nkdbd935l6zwky8jm1g68r0000gn/T/pip-fn3n3u-record/install-recor‌​d.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/m_/v2nkdbd935l6zwky8jm1g68r0000gn/T/pip_build_ben/lxml
Notice that you get the following error message:
ImportError: lxml not found, please install it
That means you need to install python-lxml package on Linux.
on Ubuntu
sudo apt-get -y install python-lxml
On Fedora
sudo yum -y install python-lxml
On Mac
brew install libxml2
brew install libxslt
STATIC_DEPS=true sudo pip install lxml
If you're on a Mac, you have to download and install the developer tools, which can be achieved with this command:
xcode-select --install
I had the same error before doing so when I did pip install lxml

Categories