How tp get pip to run in in Xubuntu - python

I've installed python 3.9 on Xubuntu 20.04 using apt. When I try to run pip, I get the error, No module named 'distutils.cmd'
For example, python3.9 -m pip --help gives the traceback
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/saul/.local/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/configuration.py", line 26, in <module>
from pip._internal.utils.logging import getLogger
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 27, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 39, in <module>
from pip._internal.locations import get_major_minor_version
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 14, in <module>
from . import _distutils, _sysconfig
File "/home/saul/.local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
Where can I find distutils.cmd and where should I put it? I'm not at all knowledgeable about linux, just a naive user.
I found this post which indicated that there isn't a separate distutils module for python3.9, and seemed to suggest using virtual environments. When I tried
python3.9 -m venv /home/saul/.venvs/py39
however, I got the message
Error: Command '['/home/saul/.venvs/py39/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py (probably will give an error, I tried and it gave an error for me)
sudo apt install python3.9-distutils
python3.9 get-pip.py (can skip and directly check the version, if it works then good otherwise run this command and then check version. I ran this command before checking version)
And finally,
python3.9 -m pip -V (should give console as pip 22.x.x from some-path (python3.9) )
I ran these commands, it worked for me. Hope it helps you too.

I stumbled on this, which worked:
sudo apt install python3.9-venv

Related

Could not find a kernel matching Python 3. Please select a kernel

After I tried to install and register a new virtual environment so I can use it in Jupyter notebook, I ended up with the following problem: any notebook I open or create it displays the error message: "Could not find a kernel matching Python 3. Please select a kernel:"
but there are no kernels registered anymore ...
I couldn't find a good answer although I noticed that many others faced the same problem in the past. Anyone could help?
I am using Ubuntu and pip.
It seems to be a configuration problem with Jupyter.
$ jupyter --paths --debug
JUPYTER_PREFER_ENV_PATH is not set, making the user-level path preferred over the environment-level path for data and config
JUPYTER_NO_CONFIG is not set, so we use the full path list for config
JUPYTER_CONFIG_PATH is not set, so we do not prepend anything to the config paths
JUPYTER_CONFIG_DIR is not set, so we use the default user-level config directory
JUPYTER_PATH is not set, so we do not prepend anything to the data paths
JUPYTER_DATA_DIR is not set, so we use the default user-level data directory
JUPYTER_RUNTIME_DIR is not set, so we use the default runtime directory
config:
/home/florian/.jupyter
/home/florian/..../OCR/ocr_env/etc/jupyter
/usr/local/etc/jupyter
/etc/jupyter
data:
/home/florian/.local/share/jupyter
jupyter kernelspec list
Available kernels:
ocr_env /home/florian/.local/share/jupyter/kernels/ocr_env
python3 /home/florian/.local/share/jupyter/kernels/python3
spark_env /home/florian/.local/share/jupyter/kernels/spark_env
tensorflow /home/florian/.local/share/jupyter/kernels/tensorflow
Another error trying to upgrade pip:
python -m pip install --upgrade pip
Traceback (most recent call last):
File "/home/florian/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/florian/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/__main__.py", line 23, in <module>
from pip._internal.cli.main import main as _main # isort:skip # noqa
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
from pip._internal.cli.progress_bars import BAR_TYPES
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 12, in <module>
from pip._internal.utils.logging import get_indentation
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/utils/logging.py", line 18, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 33, in <module>
from pip._internal.locations import (
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/__init__.py", line 9, in <module>
from . import _distutils, _sysconfig
File "/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/locations/_sysconfig.py", line 8, in <module>
from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions' (/home/florian/anaconda3/lib/python3.8/site-packages/pip/_internal/exceptions.py)
Seems I found a solution like this below:
pip3 install --force-reinstall jupyter_client
julia> import Pkg; Pkg.add("IJulia")
julia> using IJulia
julia> IJulia.notebook
💚 ❤️ 💜
Reference:
julia> is running julia.app on macOS
https://github.com/JuliaLang/IJulia.jl/issues/968#issuecomment-739800974

Failing to install and run python applications MacOS

The problem started when I wanted to install pyinstaller using pip and got the error below.
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.7 /usr/local/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/vv/cwv95ck53677_nsc37m749000000gn/T/pip-build-env-sdsbi36x/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel
cwd: None
Complete output (36 lines):
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.7/site-packages/pip/__main__.py", line 16, in <module>
from pip._internal.main import main as _main # isort:skip # noqa
File "/usr/local/lib/python3.7/site-packages/pip/_internal/main.py", line 13, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 11, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/cmdoptions.py", line 25, in <module>
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
File "/usr/local/lib/python3.7/site-packages/pip/_internal/locations.py", line 18, in <module>
from pip._internal.utils import appdirs
File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/appdirs.py", line 16, in <module>
from pip._internal.utils.compat import WINDOWS, expanduser
File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/compat.py", line 17, in <module>
from pip._vendor.urllib3.util import IS_PYOPENSSL
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 11, in <module>
from .exceptions import (
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/packages/six.py", line 199, in load_module
mod = mod._resolve()
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/packages/six.py", line 113, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/lib/python3.7/site-packages/http/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 /usr/local/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/vv/cwv95ck53677_nsc37m749000000gn/T/pip-build-env-sdsbi36x/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel Check the logs for full command output.
I tried googling the error to find a solution and I tried a suggestion of unset $PYTHONPATH and then I tried reinstalling python as a whole using brew and then tried installing pyinstaller again at which point I got the error message below and now get this message when I try installing anything using pip or running any python program. Also I am running MacOS Catalina 10.15.2.
$ python3 main.py
Error processing line 1 of /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backports.csv-1.0.6-py3.6-nspkg.pth:
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 5, in <module>
from collections import deque
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 27, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python3.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 579, in <module>
main()
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 566, in main
known_paths = addsitepackages(known_paths)
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 349, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py", line 178, in addpackage
import traceback
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/traceback.py", line 3, in <module>
import collections
File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 27, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python3.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
$ python3 --version
Python 3.7.5
If anyone can help, I would be very grateful. Thank you!
UPDATE
Upon view this question, I have decided to reinstall my OS. Thank you to those who responded which helped me refine my search and find these question.
A few suggestions (after you wipe your python from your system again):
Try installing the development version of pyinstaller in case it's a bug with them:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Forget about pip and install anaconda. Anaconda is a package manager for handling versioning and dependencies. Versioning and dependencies is the problem you are having here.
Another note: there are probably multiple versions of python on your system. I see you are running python3 there. Were you also running pip3? Make sure these are coming from the same path... do which python 3 and which pip3. Also you can find all installations of python: How to find all python installations on mac os x and uninstall all but the native OS X installation and remove them or at least make sure you aren't inadvertently using them.

Error in running a python script-In pip installation

I am running a python script where it is setting up an environment in unix to run other python scripts. It is trying to install pip and it fails with the following error.
2016-01-25 12:05:50,291 - Checking if pip is installed.
2016-01-25 12:05:50,291 - Pip is not currently installed.
2016-01-25 12:05:50,291 - Installing pip.
Traceback (most recent call last):
File "/tmp/tmpoDUDVr.py", line 19017, in <module>
main()
File "/tmp/tmpoDUDVr.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "/tmp/tmpoDUDVr.py", line 82, in bootstrap
import pip
File "/tmp/tmpm4FmfJ/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/vcs/subversion.py", line 9, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/index.py", line 29, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/wheel.py", line 39, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/scripts.py", line 14, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
Failed to install pip. Error was Command '['python', '/tmp/tmpoDUDVr.py', '- -user', '--upgrade', '--force-reinstall']' returned non-zero exit status 1
I have already installed pip using the command yum -y install python-pip but still it throws this error. I am not able to find this tmp/tmpoDUDVr.py file and everytime I run this tmp file varies.I tried searching hidden files too(ls -a) Could you please shed light? Any thoughts much appreciated..
Try to use "sudo" in this case. PIP was installed the first time as root...

exceptions import SSLError, InsecurePlatformWarning when using pip, python3.4 win32

I installed Python 3.4.0, but I can't use pip. So then I installed pip from python.org. Then I set PATH.
when I use pip, it reports these:
C:\Users\think\Downloads\pip-7.1.2>pip
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
...
File "C:\Python34\lib\site-packages\pip\_vendor\requests\packages\urllib3\conn
ectionpool.py", line 33, in <module>
from .connection import (
File "C:\Python34\lib\site-packages\pip\_vendor\requests\packages\urllib3\conn
ection.py", line 41, in <module>
from .util import (
File "C:\Python34\lib\site-packages\pip\_vendor\requests\packages\urllib3\util
\__init__.py", line 5, in <module>
from .ssl_ import (
File "C:\Python34\lib\site-packages\pip\_vendor\requests\packages\urllib3\util
\ssl_.py", line 4, in <module>
from ..exceptions import SSLError, InsecurePlatformWarning
ImportError: cannot import name 'InsecurePlatformWarning'
Python3.4.0 on Win32
Please assure that you are running pip module that was intalled in the include path of your python version.
You can do this via python -m pip install <somemodule>. If this fails you probably do not have the right module.
Also, you may want to install the modules for current user only, by using python -m pip install --user <somemodule>

ImportError while installing pip in virtualenv

I have a rhel machine with python2.6 installed on it. I've been trying to have an alternate install of python2.7 and set up a virtualenv for using 2.7. I installed python2.7 by building from source as follows:
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
I already had virtualenv installed on the system so I used it to create a venv for 2.7 as follows:
virtualenv -p python2.7 --no-setuptools py27
. py27/bin/activate
Now when I try to install pip inside the venv, it fails like so:
python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19857, in <module>
main()
File "get-pip.py", line 151, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 81, in bootstrap
import pip
File "/tmp/tmpArPs31/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/download.py", line 29, in <module>
File "/tmp/tmpArPs31/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
Can't figure out what's going wrong here. Please help.
I've installed python 2.7.8.
EDIT: I initially tried creating virtualenv without --no-setuptools option but that gave me the same error:
virtualenv -p python2.7 py27_with_pip
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in py27_with_pip/bin/python2.7
Also creating executable in py27_with_pip/bin/python
Installing setuptools, pip...
Complete output from command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0- py2.py3-none-any.whl/pip/__init__.py", line 15, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/vcs/mercurial.py", line 11, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/download.py", line 29, in <module>
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv_support/pip-6.0-py2.py3-none-any.whl/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 2363, in <module>
main()
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 848, in main
symlink=options.symlink)
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 1016, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 984, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/lib/python2.6/site-packages/virtualenv-12.0-py2.6.egg/virtualenv.py", line 926, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /data1/home/sagraw1/...th_pip/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
I tried installing pip with python2.7 directly but even that doesn't work:
python2.7 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 19857, in <module>
main()
File "get-pip.py", line 151, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 81, in bootstrap
import pip
File "/tmp/tmpPSVEkk/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/vcs/mercurial.py", line 11, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/download.py", line 29, in <module>
File "/tmp/tmpPSVEkk/pip.zip/pip/_vendor/__init__.py", line 81, in load_module
ImportError: No module named 'pip._vendor.requests'
I was in a situation similar to yours, and I eventually found the fix. At least in my case the root problem was that when I compiled python 2.7.8 the build process didn't find the proper OpenSSL libraries (because they were not installed on my system). After make finished running it showed a summary similar to this:
Failed to find the necessary bits to build these modules:
_bsddb _curses _curses_panel
_hashlib _sqlite3 _ssl
This doesn't prevent make install from working, and after that Python works just fine, except that it can't access https URLs and other related functionality. You can tell if this is your case by starting python and then typing
import ssl
If you see an ImportError, then the ssl module is missing. Otherwise, you see no message at all.
I fixed this by installing the OpenSSL libraries by running (as root):
yum install openssl-devel
After this was in place, I rebuilt Python with make (now _ssl was not listed as missing), followed by make install. After this, running get-pip.py worked without a hitch.
Hope this helps!

Categories