Install packages using setuptools and pip.main - python

I'm trying to make a setup script for a python package. For an easy setup, I would like that all the dependencies be installed using setuptools. However, I found some difficulties when installing these packages this way: numpy, matplotlib, scipy, netcdf4, pandas and pymatgen. The numpy problem was already asked in this SO post, matplotlib here, pandas here and scipy here. So it seems it is a recurring problem though I have found a workaround for each of these packages which is to use pip in the setup script:
from setuptools import pip
import pip
for package in ("numpy", "matplotlib", "scipy", "netcdf4", "pandas",
"pymatgen"):
pip.main(["install", package])
setup(name="package_name",
...)
The problem is that when another package requires this package, the fact that pip is called to install the dependencies, setuptools raises a weird SandBoxViolation Error which prevent the use of the pip.main function.
Here's an example traceback:
Traceback (most recent call last):
File ".../lib/python3.6/site-packages/pip/basecommand.py", line 215,
in main
status = self.run(options, args)
File ".../lib/python3.6/site-packages/pip/commands/install.py", line 335, in run
wb.build(autobuilding=True)
File ".../lib/python3.6/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File ".../lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File ".../lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File ".../lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File ".../lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File ".../lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File ".../lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File ".../lib/python3.6/site-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File ".../lib/python3.6/site-packages/pip/index.py", line 792, in get_page
"Cache-Control": "max-age=600",
File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 488, in get
return self.request('GET', url, **kwargs)
File ".../lib/python3.6/site-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/adapter.py", line 37, in send
cached_response = self.controller.cached_request(request)
File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/controller.py", line 202, in cached_request
self.cache.delete(cache_url)
File ".../lib/python3.6/site-packages/pip/download.py", line 302, in delete
return super(SafeFileCache, self).delete(*args, **kwargs)
File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py", line 107, in delete
os.remove(name)
File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 314, in wrap
path = self._remap_input(name, path, *args, **kw)
File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 456, in _remap_input
self._violation(operation, os.path.realpath(path), *args, **kw)
File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 411, in _violation
raise SandboxViolation(operation, args, kw)
setuptools.sandbox.SandboxViolation: SandboxViolation:
remove('/.../Library/Caches/pip/http/8/f/4/a/1/8f4a19894a92f9
63886c9b755abcf90542da3c3c8283d3bebe3650b2',) {}
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
A workaround for this is to use the pip.main method for this package also...
So I conclude that the use of the pip.main function should be avoided but I don't know an easy way to install the problematic dependencies. So my question is: how should the problematic dependencies like numpy, scipy, pymatgen, etc. be handled in order to install them automatically (without pip, just with setuptools for instance)? If it is not possible to avoid the usage of pip, how should the package calling pip in it's setup should be installed (in order to avoid the SandboxViolation errors)?

Related

pip install raise ValueError("check_hostname requires server_hostname") while VPN is on

pip install <package> gives exception.
raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
while VPN is on, let say. My only option is VPN. I can not turn it off. How to solve this problem.
Pip Version pip 21.1.1 Python 3.9.5 Conda version conda 4.10.1
Here is a full exception.
WARNING: Ignoring invalid distribution -rllib3 (c:\programdata\anaconda3\envs\pycharm\lib\site-packages)
WARNING: Ignoring invalid distribution -rllib3 (c:\programdata\anaconda3\envs\pycharm\lib\site-packages)
ERROR: Exception:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\cli\base_command.py", line 180, in _main
status = self.run(options, args)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\cli\req_command.py", line 204, in wrapper
return func(self, options, args)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
requirement_set = resolver.resolve(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 127, in resolve
result = self._result = resolver.resolve(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 473, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
name, crit = self._merge_into_criterion(r, parent=None)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _merge_into_criterion
if not criterion.candidates:
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 139, in __bool__
return bool(self._sequence)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in __bool__
return any(self)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 129, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 30, in _iter_built
for version, func in infos:
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 258, in iter_index_candidate_infos
result = self._finder.find_best_candidate(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\package_finder.py", line 879, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\package_finder.py", line 824, in find_all_candidates
page_candidates = list(page_candidates_it)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
yield from self._candidates_from_page(self._link)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\package_finder.py", line 783, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\collector.py", line 512, in fetch_page
return _get_html_page(location, session=self.session)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\collector.py", line 422, in _get_html_page
resp = _get_html_response(url, session=session)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\index\collector.py", line 120, in _get_html_response
resp = session.get(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_internal\network\session.py", line 449, in request
return super().request(method, url, *args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 53, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\connection.py", line 500, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 432, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 474, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\ProgramData\Anaconda3\envs\PyCharm\lib\ssl.py", line 997, in _create
raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
WARNING: Ignoring invalid distribution -rllib3 (c:\programdata\anaconda3\envs\pycharm\lib\site-packages)
WARNING: Ignoring invalid distribution -rllib3 (c:\programdata\anaconda3\envs\pycharm\lib\site-packages)
WARNING: Ignoring invalid distribution -rllib3 (c:\programdata\anaconda3\envs\pycharm\lib\site-packages)
You should try execute pip with --proxy paramenter like this:
pip --proxy <proxy> install <module>
Or you can try setting up environment-variables as explainded here https://pip.pypa.io/en/stable/user_guide/?highlight=proxy#using-a-proxy-server
Nevertheless, using a VPN should not prompt this kind of problemns, probably it's not well configured therefore, all the traffic doesn't go through it.
Check that you have your 0.0.0.0 IP route pointing to the vpn first.
If you use VPN try to disconnect it, it will solve the problem. VPN changes the proxy server setting.
Only solution for me was to upgrade pip via whl.
Download the latest whl and then pip installed the pip upgrade (pip-21.2.4-py3-none-any.whl) from the whl.
Once I upgraded PIP, then PIP could install as expected.
Copying additional detail from comment as per request.
Go to pypi.org and search for pip.py (pypi.org/search/?q=pip.py&o=). Download the file to your local computer (pip-21.2.4-py3-none-any.whl). Then, at prompt, "pip install ". It fixed mine. Hopefully it does yours too!
There is another better way to solve this.
Just need to upgrade pip version by using:
python -m pip install --upgrade pip

ImportError: No module named dash

I am unable to install dash in production server. In local, I have imported by
pip install dash==0.29.0
But in prod it is not working. When i am using
sudo apt-get install python dash
its showing
> "dash is already the newest version (0.5.8-2.4)"
, however while using import dash am getting
> "ImportError: No module named dash"
have also tried
sudo pip install python dash==0.29.0
but it gives below error:
Requirement already satisfied: python in /usr/lib/python2.7/lib-dynload
Collecting dash==0.29.0
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
wb.build(autobuilding=True)
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 792, in get_page
"Cache-Control": "max-age=600",
File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 501, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 643, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment
total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
The command sudo apt-get install python dash installs the system package python (correct) and the system package dash (incorrect), which is a linux shell.
After installing Python with sudo apt-get install python, to install the python package dash, you need to do sudo pip install dash==0.29.0 or sudo python -m pip install dash==0.29.0.
From what I can tell - and I am extremely green - it appears that python / environments scan for modules by filename in the appropriate "site packages" directory. I had installed Dash via command prompt for my system python and then also via the anaconda command prompt.
When I would try to import dash in Spyder through anaconda, I got this same error. I was able to fix the issue by renaming the folder that contained the init file from dash_rendered to just dash.
It would appear that then when Spyder scanned it's packages, it could identify the correct directory.
I had no trouble installing dash to python generally with the command provided from Plotly in the command line.
pip install dash==1.7.0
I can see this was a year ago and that Dash has changed a bit since then - but hopefully this helps future users whose environments aren't recognizing the module as "dash" without renaming, as in Spyder.
I had the same problem, I solved it running pip install dash on conda terminal (if you are using Anaconda).
Create a virtual environment:
virtualenv venv # creates a virtualenv called "venv"
source venv/bin/activate # uses the virtualenv
and then pip install dash
If you are using Jupyter notebook or Jupyter Lab, try to install jupyter-dash by:
pip install jupyter-dash
in the code:
from jupyter_dash import JupyterDash
pd.options.plotting.backend = "plotly"
file>NewProjectsSetup>Preferencesfornewprojects>PythonInterpreter> click on + symbol to search for packages, search for dash, install the package and you should be fine.

How to completely remove and install again PIP on MacOS Sierra (10.x)?

Had PIP working normally until few days ago.
Not sure how.
Trying to run it now and now show issues.
Adding full stack bellow of the error:
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
wb.build(autobuilding=True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 487, in _prepare_file
req_to_install, finder)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 428, in _check_skip_installed
req_to_install, upgrade_allowed)
File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/usr/local/lib/python2.7/site-packages/pip/index.py", line 792, in get_page
"Cache-Control": "max-age=600",
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 488, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 390, in send
conn = self.get_connection(request.url, proxies)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 290, in get_connection
proxy_manager = self.proxy_manager_for(proxy)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 194, in proxy_manager_for
**proxy_kwargs)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/poolmanager.py", line 367, in proxy_from_url
return ProxyManager(proxy_url=url, **kw)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/poolmanager.py", line 312, in __init__
proxy = parse_url(proxy_url)
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/url.py", line 189, in parse_url
raise LocationParseError(url)
LocationParseError: Failed to parse: user:pass
Want to try to reinstall pip completely.
What is recommended way to do it?
Your pip and Python installations are fine. What's wrong is your proxy configuration.
On OS X, both environment variables and the OS X network configuration can supply proxy information. First find out what configuration you have with:
python2.7 -c 'import urllib, pprint; pprint.pprint(urllib.getproxies())'
then look for any incorrect configuration in both your network settings (in the system configuration, check active networks for the proxies tab), and in your environment variables for *_proxy entries (http_proxy, https_proxy, etc.).
You can manually override proxies by setting one on the command line with the --proxy switch:
pip --proxy= install ...
Note the empty --proxy=; or you can set a specific proxy.
If you really did need to re-install your Python setup, you appear to have installed yours with Homebrew, so you can re-install it with brew install -f python#2.
Download Anaconda (or Miniconda), run it, and restart your terminal then start using environments.
to create an environment type
conda create -n my_project_name python=3.6
conda activate my_project_name
Now do all the pip installs and conda installs you want.
Your path is fixed. Pip is fixed. Go crazy.
Edit:
Now that you've posted your full traceback it looks like you need to feed the proxy a username and password. Here is one way to do it.
pip install --proxy=https://user#mydomain:port somepackage

Error using pip install, I can't install any package

I'm using Python 3.5 and I am trying to install some packages. I usually use conda and everything's fine when I do but some packages is not in the anaconda repository and so I then use pip (either pip or pip3).
For some reason I get this error when I try to install any package not installed:
$ pip3 install pyqt3d
Exception:
Traceback (most recent call last):
File "C:\Users\MonsterIguan\Anaconda3\lib\site- packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run
wb.build(autobuilding=True)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\req\req_set.py", line 487, in _prepare_file
req_to_install, finder)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\req\req_set.py", line 428, in _check_skip_installed
req_to_install, upgrade_allowed)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
page = self._get_page(location)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page
inst = cls(resp.content, resp.url, resp.headers)
File "C:\Users\MonsterIguan\Anaconda3\lib\site-packages\pip\index.py", line 728, in __init__
self.parsed = html5lib.parse(
AttributeError: module 'pip._vendor.html5lib' has no attribute 'parse'
I've seen some post with the same question but with inconclusive solutions. I am unfamiliar with pip/pip3 and rather scared of messing it up if I try to uninstall and install again. I still would rather use command line to install packages than manually installing with a .zip folder.
(I tried both on cmd and git bash)
First update conda:
conda update conda
then update pip with conda:
conda update pip
As a rule of thumb. Always use conda first before trying pip. That usually helps.

Cannot install and upgrade python packages on Ubuntu 14.04

I am trying to install some python packages but I am getting this kind of error every time.
The directory '/home/username/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/username/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run
requirement_set.prepare_files(finder)
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file
finder, self.upgrade, require_hashes)
File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages
page = self._get_page(location)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page
"Cache-Control": "max-age=600",
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
timeout=timeout
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
I looked it up on this site and Stack Overflow and all the solutions suggest installing
wheel
or
setuptools
But I am getting
Requirement already satisfied
The same problem occurs for trying to upgrade python packages.
Some of the commands that give me this error are:
sudo pip install -U textblob
My pip version is pip 8.1.1
What should I do?
Try, as suggested by the error message, running:
sudo -H pip install -U textblob
It is also well worth making sure that your version of pip is up to date with:
sudo python -m pip install -U pip
or
sudo -H python -m pip install -U pip
This happens to me frequently. Try this:
pip install textblob --user
This will work fine with other packages as well.
Thanks !

Categories

Resources