Distutils was imported before Setuptool error - python-3.x

After upgrading pip on python3.5 I am getting the message
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 57 sys.stderr.write(f"ERROR: {exc}")
I tried the solution in
pip: sys.stderr.write(f"ERROR: {exc}") with Python 3.5
However when I try
sudo curl -fsSL https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.5
I get
/usr/local/lib/python3.5/dist-packages/_distutils_hack/__init__.py:18:
UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.`
`"Distutils was imported before Setuptools, but importing Setuptools "
/usr/local/lib/python3.5/dist-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
File "<stdin>", line 23974, in <module>
File "<stdin>", line 199, in main
File "<stdin>", line 121, in bootstrap
File "/usr/local/lib/python3.5/dist-packages/setuptools/__init__.py", line 8, in <module>
import _distutils_hack.override # noqa: F401
File "/usr/local/lib/python3.5/dist-packages/_distutils_hack/override.py", line 1, in
<module>
__import__('_distutils_hack').do_override()
File "/usr/local/lib/python3.5/dist-packages/_distutils_hack/__init__.py", line 72, in do_override
ensure_local_distutils()
File "/usr/local/lib/python3.5/dist-packages/_distutils_hack/__init__.py", line 59, in ensure_local_distutils
assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/lib/python3.5/distutils/core.py ```
Any ideas?

Related

ImportError: cannot import name '_adapters' from partially initializer module importlib_metadata' (most likely due to a circular import)

I was updating my Pypi package using:
python setup.py sdist bdist_wheel
Then, running:
python -m twine upload --https://github.com/ERijck/FuzzyTM https://test.pypi.org/legacy/ dist/*
Returned the following error:
(base) C:\Users\Emil\surfdrive\PhD\3. Python Scripts\GitHub\FuzzyTM>python -m twine upload --https://github.com/ERijck/FuzzyTM https://test.pypi.org/legacy/ dist/*
Traceback (most recent call last):
File "C:\Users\Emil\Anaconda3\lib\runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Users\Emil\Anaconda3\lib\runpy.py", line 144, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Users\Emil\Anaconda3\lib\runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "C:\Users\Emil\AppData\Roaming\Python\Python38\site-packages\twine\__init__.py", line 32, in <module>
import importlib_metadata
File "C:\Users\Emil\Anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 17, in <module>
from . import _adapters, _meta
ImportError: cannot import name '_adapters' from partially initialized module 'importlib_metadata' (most likely due to a circular import) (C:\Users\Emil\Anaconda3\lib\site-packages\importlib_metadata\__init__.py)
Based on the error and on this link it seems that I have a circular import. How can I fix this?
The problem was not a circular input. Having an older version of importlib_metadata installed caused the issue.
pip install -U importlib_metadata solved it.

python3 path only running google-appengine modules

When running django projects with python3 or installing modules with pip, I am getting google-appengine errors, even if my project is not using google appengine.
When running pip3 freeze I get the following results:
andrew#andrew:~/dev/quickistock$ pip3 freeze
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/home/andrew/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/andrew/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/andrew/.local/lib/python3.5/site-packages/pip/locations.py", line 10, in <module>
from distutils.command.install import install, SCHEME_KEYS # noqa
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py", line 258
raise DistutilsOptionError, \
^
SyntaxError: invalid syntax
The file usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py has lines like this and is compatible with python 2.1. Note. this is not the official google repository but it's accurate:
print "config vars:"
This means that install.py is a python 2 file and you are running pip from python 3. There probably is some incompatibility between them.

Python3.6 error when we are passing csv file

While reading csv file in python3.6 this error throws:
KeyError: 'result'
Error in sys.excepthook:
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "main.py", line 117, in <module>
extractPreservationDataAndSet(l.getPreservationData(), test_response);
File "main.py", line 21, in extractPreservationDataAndSet
result = temp_http_response[i];
KeyError: 'result'
How can we solve it ?
ModuleNotFoundError: No module named 'apt_pkg'
indicates you don't have the apt_pkg module installed. Have a look at the home page of that package. There is a link on how to install it using the package manager.
The easiest way to install the module is probably:
pip3 install python-apt
This solved mine issue:
python3 -c "import nltk; nltk.download('all')"
it downloaded and unzipped all the packages.

Can not run virtualenv successfully on win10

I use python36 and win10, I can install virtualenv successfully. But when I want to activate it, some mistakes have occurred.
$pip install virtualenv
Requirement already satisfied: virtualenv in c:\users\appdata\local\programs\python\python36\lib\site-packages
$virtualenv venv
Using base prefix 'c:\\users\\appdata\\local\\programs\\python\\python36'
New python executable in C:\Users\myvenv\venv\Scripts\python.exe
Installing setuptools, pip, wheel...
Complete output from command C:\Users\myvenv\venv\Scripts\python.exe - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
ModuleNotFoundError: No module named 'pkgutil'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\AppData\Local\Programs\Python\Python36\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 713, in main
symlink=options.symlink)
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 945, in create_environment
download=download,
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command C:\Users\myvenv\venv\Scripts\python.exe - setuptools pip wheel failed with error code 1
Why is there such a problem?
In fact, you don't need to reinstall your python, instead, you can just entry virtualenv envname --no-setuptools --no-pip --no-wheel in your cmd line, hope be helpful.

Jython ImportError: No module named urllib

Just installed Jython 2.7beta3 and pip under Jython in mac os x
try to run /usr/local/Cellar/jython/2.7-b3/libexec/bin/pip install requests
Get error:
Traceback (most recent call last):
File "./pip", line 8, in <module>
sys.exit(
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 519, in load_entry_point
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2630, in load_entry_point
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2310, in load
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2316, in resolve
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/pip-6.0.6-py2.7.egg/pip/__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/pip-6.0.6-py2.7.egg/pip/vcs/__init__.py", line 8, in <module>
from pip._vendor.six.moves.urllib import parse as urllib_parse
ImportError: No module named urllib
I found I can't install anything by pip under jython.
Please help me fix it, thanks.
I had the same problem trying to use pip for Jython2.7b3.
I downloaded this:
https://github.com/jythontools/pip/tree/master
And ran the command:
Jython setup.py install
And pip is now up and running like a charm.

Resources