PIP3 list failed completely and returing error - python

After I run "pip3 install rsa==3.4.2". I cannot use "pip3 list" command any more and pretty much any pip command will fail.
The error is like the following
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2584, in version
return self._version
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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.5/lib/python3.5/site-packages/pip/_internal/cli/base_command.py", line 176, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_internal/commands/list.py", line 148, in run
self.output_package_listing(packages, options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_internal/commands/list.py", line 205, in output_package_listing
data, header = format_for_columns(packages, options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_internal/commands/list.py", line 271, in format_for_columns
row = [proj.project_name, proj.version]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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.5/lib/python3.5/site-packages))
I don't have any clue so far. I wonder if there is an solution to this?
Thanks

I had same issue and solved by following,
python3 -c "import site; print(site.getsitepackages())"
will list the location of site-packages,
['/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages', '/Library/Python/3.6/site-packages']
and check the invalid directories,
cd /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
find . -name METADATA
for me ./-ip-18.1.dist-info/pip-18.1.dist-info/METADATA was the problem and I deleted the directory.
rm -rf ./-ip-18.1.dist-info
everything seems to be fine now.

Related

Pyinstaller can't find package importlib_metadata

I created a new poetry project.
main.py:
import importlib_metadata
PACKAGE_NAME = 'try_pyinstaller'
def get_version():
version = importlib_metadata.version(PACKAGE_NAME)
return version
def main():
version = get_version()
print(version)
if __name__ == "__main__":
main()
when I run pyinstaller with:
pyinstaller --onefile --name main try_pyinstaller\main.py --clean
i get the error:
C:\Users\micha\voltfang_software\tests\python\try_pyinstaller\dist>main.exe
Traceback (most recent call last):
File "importlib_metadata\__init__.py", line 381, in from_name
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "try_pyinstaller\main.py", line 14, in <module>
File "try_pyinstaller\main.py", line 10, in main
File "try_pyinstaller\main.py", line 6, in get_version
File "importlib_metadata\__init__.py", line 832, in version
File "importlib_metadata\__init__.py", line 805, in distribution
File "importlib_metadata\__init__.py", line 383, in from_name
importlib_metadata.PackageNotFoundError: No package metadata was found for try_pyinstaller
[2576] Failed to execute script 'main' due to unhandled exception!
The wierd thing is when I just change variable in version = importlib_metadata.version(PACKAGE_NAME) to version = importlib_metadata.version('try_pyinstaller') it works totally fine. Same environment, nothing else changed. Just put the hardcoded string in.
is this a bug or am I doing something wrong?
The answer to this question can be found here:
https://github.com/pyinstaller/pyinstaller/issues/7399
In short:
If you use importlib_metadata.version('try_pyinstaller'), PyInstaller's bytecode scanning can infer that metadata for try_pyinstaller needs to be collected. If you use a variant with non-literal argument, importlib_metadata.version(PACKAGE_NAME), it cannot do that, and you need to explicitly instruct it to collect metadata via --copy-metadata try_pyinstaller.

Need help installing pyrate for Python on Windows 10, getting error message

I need help installing pyrate. I have Windows 10 and installed python 3.9.2 and am trying to install pyrate by following the instructions from:
https://github.com/mess42/pyrate
I have followed the install instructions up until the fourth and final command, which is 'pip install [-e] .'. After entering the command I get the following error message:
ERROR: Exception:
Traceback (most recent call last):
File "d:\python\lib\site-packages\pip\_vendor\packaging\requirements.py", line 113, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "d:\python\lib\site-packages\pip\_vendor\pyparsing.py", line 1955, in parseString
raise exc
File "d:\python\lib\site-packages\pip\_vendor\pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected stringEnd, found '[' (at char 11), (line:1, col:12)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\python\lib\site-packages\pip\_internal\cli\base_command.py", line 189, in _main
status = self.run(options, args)
File "d:\python\lib\site-packages\pip\_internal\cli\req_command.py", line 178, in wrapper
return func(self, options, args)
File "d:\python\lib\site-packages\pip\_internal\commands\install.py", line 287, in run
reqs = self.get_requirements(args, options, finder, session)
File "d:\python\lib\site-packages\pip\_internal\cli\req_command.py", line 340, in get_requirements
req_to_add = install_req_from_line(
File "d:\python\lib\site-packages\pip\_internal\req\constructors.py", line 391, in install_req_from_line
parts = parse_req_from_line(name, line_source)
File "d:\python\lib\site-packages\pip\_internal\req\constructors.py", line 332, in parse_req_from_line
extras = convert_extras(extras_as_string)
File "d:\python\lib\site-packages\pip\_internal\req\constructors.py", line 64, in convert_extras
return Requirement("placeholder" + extras.lower()).extras
File "d:\python\lib\site-packages\pip\_vendor\packaging\requirements.py", line 115, in __init__
raise InvalidRequirement(
pip._vendor.packaging.requirements.InvalidRequirement: Parse error at "'[-e]'": Expected stringEnd
Can someone please help. Thanks.
You need to type either
pip install .
or
pip install -e .
-e means edit mode,
and it is optional that's why it is written in square brackets as [-e].
If you want to edit the module as you use pip install -e . otherwise go for pip install .

Python Pylenium package installation failure: "AttributeError: 'Scheme' object has no attribute 'conftest.py'"

Trying to install package with following command and got an error
pip install pyleniumio
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
status = self.run(options, args)
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
return func(self, options, args)
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 407, in run
use_user_site=options.use_user_site,
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\req\__init__.py", line 71, in install_given_reqs
**kwargs
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\req\req_install.py", line 811, in install
direct_url=direct_url,
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\install\wheel.py", line 630, in install_wheel
direct_url=direct_url,
File "c:\users\mi\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\install\wheel.py", line 452, in install_unpacked_whee
l
dest = getattr(scheme, subdir)
AttributeError: 'Scheme' object has no attribute 'conftest.py'
Some python packages require other ways, for example, the POT package requires a specific C++ compiler to install. Make sure you read the entire instructions and have everything you need. Another thing that works for me if you have all the requirements and you are running Linux like me, you can just simply lead your terminal to where the file is and just run for example python package.py and it installs. Hopefully, this helped you and you can install your package.

Python external on Azure ImportError No Module Found

If i locally run my code with python main.py, then this error occurs locally. If i run it with python3 main.py, it works as expected. I suspect my azure app service is not running the correct version of python, however, it is set to python 3.4
StdErr:
2018-06-30 19:47:13.785205: Unhandled exception in wfastcgi.py: Traceback (most recent call last):
File "D:\Python34\Scripts\wfastcgi.py", line 711, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\Python34\Scripts\wfastcgi.py", line 568, in read_wsgi_handler
return env, get_wsgi_handler(handler_name)
File "D:\Python34\Scripts\wfastcgi.py", line 541, in get_wsgi_handler
handler = handler()
File ".\ptvs_virtualenv_proxy.py", line 120, in get_venv_handler
handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
File ".\ptvs_virtualenv_proxy.py", line 89, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "main.app" could not be imported: Traceback (most recent call last):
File ".\ptvs_virtualenv_proxy.py", line 73, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File "D:\home\site\wwwroot\main.py", line 2, in <module>
from newspaper import Article
ImportError: No module named 'newspaper'
UPDATE
So I went to the debug console in kudo and i ran python
-m pip install --upgrade -r d:\home\site\wwwroot\requirements.txt.
Here is the error
ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt
One of the requirements is Pillow which requires libxml2 and libxslt. I've tried using wheels however, I've had no success.
UPDATE II
I tried to install virtualenv since it does not exist and I receive a permissions error.
UPDATE III
I ran this command
D:\home\python364x64>python -m pip install newspaper3k
I test everything locally, and it works perfect. I push and receive this error below.
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "D:\home\python364x64\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\home\python364x64\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "D:\home\python364x64\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\app.py", line 8, in <module>
from newspaper import Article
File "D:\home\python364x64\lib\site-packages\newspaper\__init__.py", line 10, in <module>
from .api import (build, build_article, fulltext, hot, languages,
File "D:\home\python364x64\lib\site-packages\newspaper\api.py", line 12, in <module>
import feedparser
File "D:\home\python364x64\lib\site-packages\feedparser.py", line 316
raise KeyError, "object doesn't have key 'category'"
^
SyntaxError: invalid syntax
StdOut:
StdErr:
Per my experience, we have no permission to modify D:\home environment.
So , It's better to use python extension. Please follow the steps in this case: Azure Flask Routes Not found and use command python -m pip install newspaper to install additional packages in python extension.
Please make sure the package you want to install must match with version of python extension. Otherwise, it will throw error as follows.
Hope it helps you.

Install Pyicu in python 3.x

My system is Windows 10 x64
Now I would like to install pyicu but I encounter with a problem like this
Collecting pyicu
Using cached PyICU-1.9.7.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 12, in
ICU_VERSION = os.environ['ICU_VERSION']
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\os.py", line 725, in getitem
raise KeyError(key) from None
KeyError: 'ICU_VERSION'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 26, in <module>
ICU_VERSION = check_output(('icu-config', '--version')).strip()
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 316, in check_output
**kwargs).stdout
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 383, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\ANHVU\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ANHVU\AppData\Local\Temp\pip-build-v5fb9ri4\pyicu\setup.py", line 33, in <module>
''')
RuntimeError:
Please set the ICU_VERSION environment variable to the version of
ICU you have installed.
How can I resolve this? Help me pls.
You can download a corresponding whl file from Unofficial Windows Binaries for Python Extension Packages
For example, the latest version (as of Jan 13 2019) for your 64-bit Windows and Python3.7 version is PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
Then open the Windows Powershell console as Administrator, cd to the directory where you put the whl file and execute the following command:
python -m pip install .\PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
or (if you already have a previous PyICU version installed)
python -m pip install -U .\PyICU‑2.2‑cp37‑cp37m‑win_amd64.whl
For the record:
My system (Win 10, 64 bit, python 3.8) gave me the exact same error message.
The solution was to install the 32-bit version of the PyICU whl file, not the 64 bit version.

Categories