Pip not able to find wheel - python

I have a virtual environment. Since a couple of days I cannot run any pip commands and am getting the error:
File "env/bin/pip", line 7, in <module>
from pip import main
File "/env/lib/python2.7/site-packages/pip/__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/env/lib/python2.7/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/env/lib/python2.7/site-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
ImportError: No module named wheel
I have wheel in the site-packages and it was installed earlier. how do I resolve this? I cannot use any pip commands.

Your pip installation appears to be broken. It is not the wheel project that is the problem here, it is the pip.wheel package (part of pip itself) that fails to import; it looks like /env/lib/python2.7/site-packages/pip/wheel.py is either missing or has been corrupted somehow.
I'd reinstall pip at this point.

Related

Virtualenv: distutils.util not found but is installed

I'm sorry to make another thread on a question that seems to have been asked many times but I've read many and still can't figure out how to resolve it.
I'm using virtualenv 20.15.0+ds to make a venv in python 3.9
┌──(venv)─(marco㉿kali)-[~/tools/OldProgram]
└─$ python --version
Python 3.9.13
But this error occurs:
┌──(venv)─(marco㉿kali)-[~/tools/OldProgram]
└─$ pip list
Traceback (most recent call last):
File "/home/marco/tools/OldProgram/venv/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/home/marco/tools/OldProgram/venv/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/marco/tools/OldProgram/venv/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/marco/tools/OldProgram/venv/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/marco/tools/OldProgram/venv/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 18, in <module>
from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
but distutils is installed
┌──(venv)─(marco㉿kali)-[~/tools/OldProgram]
└─$ sudo apt install python3-distutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-distutils is already the newest version (3.10.8-1).
0 upgraded, 0 newly installed, 0 to remove and 1398 not upgraded.
so it's a version problem? And if yes, can I install another version isolated in the virtualenv?
(I also tried to change the version of pip and other version of python but still remain the same problem.)

how do install python packages using python3.11 -m pip

I am trying to install a python application (elastalert2) which requires the latest version of python on an Ubuntu 20.04 machine.
I have managed to install python3.11 and my searching suggested strongly that to install packages in this environment I should use python3.11 -m pip install but when I try I get:
elastalert#secmgrtst02:~$ /usr/bin/python3.11 -m pip install elastalert2==2.9.0
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal.cli.main import main as _main # isort:skip # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
I have very limited experience with python and do not know what the problem is.
I actually want the app installed in the current directory and initially (before I realised I need 3.11 I used pip3 install -t . elastalert3 which worked fine but would not run...
It is not recommended to install Python packages directly at the system level. It is recommended to install packages (libraries, dependencies) in a so-called "virtual environment".
So I would recommend you do the following:
python3.11 -m venv ~/my-python-environment
~/my-python-environment/bin/python -m pip install elastalert2==2.9.0
And from then on you call the python binary in that environment, to work with the library you just installed:
~/my-python-environment/bin/python -m elastalert.elastalert
You can create as many such environments as you need or want. You can place them wherever you want on your file system, but you can not move them after creation.
You can read more:
https://realpython.com/python-virtual-environments-a-primer/
https://docs.python.org/3/library/venv.html

cannot import zipline package after successful conda installation

python version -3.5.6
using anaconda, c++build tools are installed
pip install zipline works perfectly
import zipline # gives error below
(myenv) c:\users>>>pip show zipline
Name: zipline
Version: 1.4.1
Summary: A backtester for financial algorithms.
Home-page: https://zipline.io
Author: Quantopian Inc.
Author-email: opensource#quantopian.com
License: Apache 2.0
Location: c:\users\user\anaconda3\envs\ziplinerr\lib\site-packages
Requires: pip, setuptools, Logbook, click, six, python-interface, multipledispat
ch, toolz, numpy, pandas, pandas-datareader, scipy, patsy, statsmodels, empyrica
l, pytz, iso3166, trading-calendars, requests, sqlalchemy, alembic, bcolz, h5py,
tables, lru-dict, intervaltree, bottleneck, networkx, numexpr, iso4217
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\__init_
_.py", line 29, in <module>
from .utils.run_algo import run_algorithm
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\utils\r
un_algo.py", line 20, in <module>
from zipline.data import bundles
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\data\bu
ndles\__init__.py", line 2, in <module>
from . import quandl # noqa
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\data\bu
ndles\quandl.py", line 16, in <module>
from . import core as bundles
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\data\bu
ndles\core.py", line 15, in <module>
from ..minute_bars import (
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\zipline\data\mi
nute_bars.py", line 24, in <module>
import h5py
File "C:\Users\User\anaconda3\envs\ziplinerr\lib\site-packages\h5py\__init__.p
y", line 36, in <module>
from ._conv import register_converters as _register_converters
File "h5py\h5r.pxd", line 21, in init h5py._conv
File "h5py\_objects.pxd", line 12, in init h5py.h5r
File "h5py\_objects.pyx", line 1, in init h5py._objects
ImportError: DLL load failed: The specified procedure could not be found.
this worked for me:
# Create environment
conda create -n zipline_env python=3.6 ipykernel
# Activate environment, make sure you can see it in jupyter notebooks
conda activate zipline_env
python -m ipykernel install --user --name=zipline_env
# Install Zipline
conda install -c conda-forge zipline
If I swapped the order of the steps, it didn't work. After the above order is complete, then conda installing packages I want works fine, like jupyter, matplotlib, etc.

Python3.7 on Windows Ubuntu Bash shell ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)

I've recently updated Python to version 3.7 from version 3.5, and made it the default in my bash shell. I've also updated pip and made sure it uses Python3.7.
Now, whenever I try to install any module using pip I get this error"
$pip3 install google
Traceback (most recent call last): File "/home/AnnaK/.local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa File "/usr/lib/python3/dist-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link File "/usr/lib/python3/dist-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext File "/usr/lib/python3/dist-packages/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/scripts.py", line 14, in <module> File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/compat.py", line 66, in <module> ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)
I get the same error if I try to simply run pip. This didn't happen when I was using python3.5. I did have this problem when briefly using python2.7, but I fixed it using https://askubuntu.com/questions/581999/pip-raises-importerror-cannot-import-name-httpshandler. That solution doesn't seem to work for python3.7.
I've tried to reinstall pip, reinstall python3, update my Windows Ubuntu subsystem, and reinstall libssl-dev. I'm stumped. Any help is appreciated!
You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)
pip x.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer and is not a file managed by pip.
You can read more about this on pip's issue tracker
You'll probably want to not upgrade your system pip and instead use a virtualenv.
To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.
It should work fine if you use the first approach python3 -m pip ... instead of pip3 ....

pip installing eyeD3 module. Failed to find libmagic

Trying to install eyed3 but it's giving me this error:
>>> import eyed3
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import eyed3
File "C:\Users\Dylan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\eyed3\__init__.py", line 35, in <module>
from .utils.log import log # noqa
File "C:\Users\Dylan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\eyed3\utils\__init__.py", line 27, in <module>
import magic
File "C:\Users\Dylan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\magic.py", line 176, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
Here's the pip install:
I tried to uninstall with pip and delete all the eyed3 files, then re-install and it still gave the same error. It also does the same thing with easy_install.
On Windows
You'll need DLLs for libmagic. #julian-r has uploaded a version of this project that includes binaries to pypi: https://pypi.python.org/pypi/python-magic-bin/0.4.14
pip install python-magic-bin==0.4.14
Works for me.
I fixed it by installing libmagic with this command
brew install libmagic
You need to install libmagic before you install eye3d.
Here is a link to the git.
https://github.com/ahupp/python-magic#dependencies
You can use this to install it:
pip install python-magic

Categories

Resources