Can't uninstall global python3.5 module after upgrading to python3.6 - python-3.x

I recently upgraded from Ubuntu 17.04 to 17.10 in order to be able receive the patches for meltdown. This upgrade automatically bumped me from python3.5 to python3.6, which I don't have any problem with. However, I do have to go through and reinstall all the little tools I used. One is being troublesome.
I use a tool called tmuxp, and the official install instructions are pip install --user tmuxp. However, it seems that some time ago I install tmuxp globally on my python3.5, and it now has an executable in my /user/local/bin:
➜ maynard#buddha ~ which tmuxp
/usr/local/bin/tmuxp
This means that even after running pip install --user tmuxp, when I run tmuxp I get a DistributionNotFound error.
➜ maynard#buddha ~ tmuxp
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 658, in _build_master
ws.require(__requires__)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 972, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 863, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (tmuxp 1.3.5 (/home/maynard/.local/lib/python3.6/site-packages), Requirement.parse('tmuxp==1.3.2'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/tmuxp", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3049, in <module>
#_call_aside
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3033, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3062, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 660, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 673, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 858, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'tmuxp==1.3.2' distribution was not found and
is required by the application
So the old python3.5 tmuxp binary is going and looking in the new python3.6 site-packages for an older version of itself. This should be an easy fix. Simply uninstall the python3.5 version of tmuxp. But when I use pip3.5 is tries to uninstall the python3.6 tmuxp.
pip3.5 uninstall tmuxp
Uninstalling tmuxp-1.3.5:
/home/maynard/.local/bin/tmuxp
/home/maynard/.local/lib/python3.6/site-packages/tmuxp-1.3.5.dist-info/DESCRIPTION.rst
...
/home/maynard/.local/lib/python3.6/site-packages/tmuxp/workspacebuilder.py
In fact, a pip3.5 list doesn't even show tmuxp, but I can see it in /usr/local/lib/python3.5/dist-packages!
ls /usr/local/lib/python3.5/dist-packages
click kaptan powerline
click-6.7.dist-info kaptan-0.5.8.egg-info powerline_status-2.6.egg-info
colorama libtmux tmuxp
colorama-0.3.9.dist-info libtmux-0.7.4.egg-info tmuxp-1.3.2.egg-info
Invoking sudo doesn't work either. sudo ~/.local/bin/pip3.5 uninstall tmuxp once again tries to uninstall the python3.6 version of tmuxp.
I know I could just delete the binary in /usr/local/bin/tmuxp... But I want to know how I got myself into this mess and how I can get out of it cleanly.

tmuxp didn't exist officially in Ubuntu until 18.04 bionic (LTS).
/usr/lib/python3/dist-packages
Do you have tmuxp installed through apt / apt-get through some other method? If so, see what sudo apt-get remove tmuxp does.
If you don't have the apt package to tmuxp, I'm concerned about your system's python installation.
Backtracking using history(1) + grep(1)
To find out how and why the system's python packages got borked depends on the commands you ran in the past. Hopefully you still have a shell history of when you installed.
If you look in your Bash history for tmuxp by piping to grep(1), e.g. history | grep tmuxp, can you see commands for how you could have ended up with it previously?
My hunch is you may have used easy_install, which in 2022 isn't used anymore.
Cleaning up old packages
I prefer clean installs over upgrades with Ubuntu, namely to avoid issues like this. It's not as painful in recent releases.
#hoefling's comment is on track. It seems you need to install python 3.5 again. This answer has some ways to get 3.5 working again. Afterwards, you can then install it.

Related

pkg_resources.DistributionNotFound: The 'platformdirs<3,>=2' distribution was not found and is required by virtualenv

I am trying to create an isolated environment using pip, the instructions from "Hands on Machine Learning With Ski-Kit and Tensor Flow" have me run these lines of code and this is the output I get. I've tried uninstalling pipenv and that creates another error where pipenv command not found. Not sure how to work around this, can anyone help? I'm using a Mac with python3.9
Darrens-MacBook-Air:~ odonned4$ cd $ML_PATH
Darrens-MacBook-Air:~ odonned4$ virtualenv env
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 585, in _build_master
return cls._build_from_requirements(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 598, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'platformdirs<3,>=2' distribution was not found and is required by virtualenv```
What is the problem?
You are trying to run Python 3.9, right? Well, according to your error message, it seems like you're invoking Python 2.7:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
^^^
This confusion happens because macOS added Python 2.7 to the distribution for... compatibility reasons. And, probably, you have virtualenv on that distribution, but you don't have platformdirs, so creating a virtualenv fails.
How to solve the problem?
There are many ways to clarify this confusion. A good way is using python3 -m virtualenv (instead of virtualenv). That should create a virtualenv with Python 3.
Also, you can get sure that the virtualenv package is available in your Python 3.9 installation. To identify that, see if virtualenv appears when typing python3 -m pip list. If not, run python3 -m pip install virtualenv.
The real problem here is that Mac is hard wired to use python2. When using virtualenv, you might have run the command:
$ /usr/bin/easy_install virtualenv
which should have added virtualenv to the /usr/bin/ for direct use, but to be used with the default python2 instead of python3.9 which you might have installed on your own.
A simple way around is to use
$ python3 -m virtualenv <env-name>
instead of
$ virtualenv <env-name>
Or in my case, add an alias in .bash_profile:
$ alias virtualenv="python3 -m virtualenv"
which is a duct tape solution but it works as well.
Try uninstalling setuptools with
pip uninstall -y setuptools
and reinstalling it with
pip install setuptools
OR
Upgrade setuptools with
pip install --upgrade setuptools
OR
For me i have faced this issue some before in python 3.8.
I fixed it by
sudo apt install --reinstall python3-pkg-resources python3-setuptools
OR
Uninstall virtualenv and setuptools first and find pip cache folder.
pip cache dir
Delete the cache and install virtualenv and setuptools.
I JUST SAID SOME STEPS .. TRY THIS . MAY HELP : )

unable to install matplotlib with python3 on m1 mac using pip3

I'm unable to install matplotlib through pip on my M1 Mac. I have Python 3.9.1 installed through Homebrew. I've tried the solution here: Pip install matplotlib fails on M1 Mac but it does not work for me.
I get this long error:
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
/opt/homebrew/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 256, in <module>
setup( # Finally, pass this all along to distutils to do the heavy lifting.
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 299, in run
self.find_sources()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 306, in find_sources
mm.run()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 541, in run
self.add_defaults()
File "/opt/homebrew/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 577, in add_defaults
sdist.add_defaults(self)
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/sdist.py", line 228, in add_defaults
self._add_defaults_ext()
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/sdist.py", line 311, in _add_defaults_ext
build_ext = self.get_finalized_command('build_ext')
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 299, in get_finalized_command
cmd_obj.ensure_finalized()
File "/opt/homebrew/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 107, in ensure_finalized
self.finalize_options()
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 88, in finalize_options
self.distribution.ext_modules[:] = [
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setup.py", line 91, in <listcomp>
for ext in package.get_extensions()
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setupext.py", line 345, in get_extensions
add_numpy_flags(ext)
File "/private/tmp/pip-install-mrz7uc56/matplotlib_20151701613b4e6fb6955488fa89e81e/setupext.py", line 468, in add_numpy_flags
import numpy as np
File "/opt/homebrew/lib/python3.9/site-packages/numpy/__init__.py", line 145, in <module>
from . import core
File "/opt/homebrew/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
I am able to import matplotlib with python 2.7 on my Rosetta Terminal but I am trying to use matplotlib with python3 instead.
Any help would be appreciated!
November 2021 Update
Just run the following command:
$ pip3 install matplotlib
Worked on Mac mini (M1, 2020), Monterey 12.0.1. Python 3.9.7
Feb 2021 Answer Below
In order to install matplotlib with pip3 on an M1 mac, you first need to install the dependencies Cython, numpy and Pillow from source. The following method worked for me.
Install Cython
pip3 install Cython
Install numpy
$ git clone https://github.com/numpy/numpy.git
$ cd numpy
$ pip3 install . --no-binary :all: --no-use-pep517
Install Pillow
libjpeg is necessary for Pillow so you might want to install it via brew.
$ brew install libjpeg
$ git clone https://github.com/python-pillow/Pillow.git
$ cd Pillow
$ pip3 install . --no-binary :all: --no-use-pep517
Install matplotlib
$ git clone https://github.com/matplotlib/matplotlib.git
Then you need to manually download qhull and extract the archive. (http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz on Qhull Downloads)
You will get a folder named qhull-2020.2. You then have to place the folder at matplotlib/build. The build folder may not exist so you might have to create it.
Lastly, the following command will install the matplotlib on your M1 mac.
$ cd matplotlib
$ pip3 install . --no-binary :all:
Tested for Python 3.9.1 on non-Rosetta terminal on M1 Mac mini (Big Sur 11.2.1).
I solved this by just uninstalling homebrew first and downloaded matplotlib with python3. After that i reinstalled homebrew using non-rosetta terminal. Idk how it works cause im very new to these stuff but what works works i guess.
I solved this by realizing that I had two seperate Python instances installed. When you run which python3 you get the path of your Python installation. Check to see if the path corresponds to the Python version you installed.
I fixed it by uninstalling the version of Python3 I had installed with homebrew with brew uninstall python3.
When I did which python3 again it showed a different Python installation path. I then did pip3 install Matplotlib and I was able to import Matplotlib.
1. Uninstall Following Package
pip uninstall pillow
pip uninstall numpy
pip uninstall wordcloud
pip uninstall matplotlib
pip uninstall pyparsing
pip uninstall kiwisolver
pip uninstall python-dateutil
pip uninstall cycler
pip uninstall packaging
pip uninstall fonttools
pip uninstall contourpy
pip uninstall six
2. Install matplotlib
pip install matplotlib
I originally installed python 3.9 using homebrew, but my matplotlib problem was fixed by uninstalling python and reinstalling using the download from the python website(because of architecture problems).
I found another nice way with pyenv,miniforge and conda.
pyenv install miniforge3-4.10
conda create -n env_new python=3.9
conda activate env_new
conda install poetry
peotry new project
poetry add matplotlib
Maybe it is not perfect, but it works for a variety of moduls and you can even choose python=3.8 and other python versions and everything is running on the M1.

Unable to import Pytorch in Jetson nano (ubuntu)

I having trouble importing PyTorch in my jetson nano (jetpack 4.4, Cuda 10.2.89), I have successfully installed it from .whl file and it is in my pip3 lib. But when I import it, it shows this error. Please help.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/parikshit/.local/lib/python3.6/site-packages/torch/__init__.py", line 188, in <module>
_load_global_deps()
File "/home/parikshit/.local/lib/python3.6/site-packages/torch/__init__.py", line 141, in _load_global_deps
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
File "/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory```
Try to do the following:
cd /home/parikshit/.local/lib/python3.6/site-packages/torch
ls
# You should find a .so file. Run the following command on that file
ldd the_file_you_found.so
#In the output you should see "not found"
#To find out which apt packages provide this .so:
sudo apt install apt-file
sudo apt-file update
#Now search for that "not found" library file. Example:
apt-file search blah.so.100
#In the first part of each line you will see the name of the file that you need to install. Example:
sudo apt install lib-hello
#Enjoy!
cd /home/parikshit/.local/lib/python3.6/site-packages/torch ls
# You should find a .so file. Run the following command on that file ldd the_file_you_found.so
#In the output you should see "not found"
#To find out which apt packages provide this .so: sudo apt install apt-file sudo apt-file update
#Now search for that "not found" library file. Example: apt-file search blah.so.100
#In the first part of each line you will see the name of the file that you need to install. Example: sudo apt install lib-hello
#Enjoy!
The previous answer resolve my issue about not finding libmpi_cxx.so.20 on Jetson Nano but I have encountered a different error while importing torch.
Error is: from torch._C import * ImportError: numpy.core.multiarray
failed to import
If you have problem importing torch because of failed to import numpy follow the step below.
pip install numpy -I
You can check the issue on GitHub for details.

Unable to download mongo-connector using pip

I am trying to install mongo-connector on Amazon-EC2 instance using the following command:
pip install mongo-connector
But following error flashes up everytime:
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 31 7, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 736, in install
requirement.uninstall(auto_confirm=True)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 742 , in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 1 15, in remove
renames(path, new_path)
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/usr/lib64/python2.7/shutil.py", line 300, in move
rmtree(src)
File "/usr/lib64/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/usr/lib64/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/dist-packages/request s/sessions.pyo'
I thought this might be some issue with root permissions, so I tried :
sudo pip install mongo-connector
But this says ,
sudo: pip: command not found
I am using pip 8.1.2, Python 2.7.12.
Any help would be appreciated!
I solved this by using the following command:
sudo `which pip`install mongo-connector
You shouldn't be using sudo to install packages with pip. While it works, it's modifying files that should be managed by your OS package manager which isn't desirable -- see also https://stackoverflow.com/a/21056000/1931274.
If you pass --user to that command, you'll be able to install without permission issues:
pip install --user mongo-connector
Moreover, newer versions of pip (installable via pip install --user pip or using get-pip.py) print a better, more helpful message when such errors occur.
For windows download required precompiled python packages from https://www.lfd.uci.edu/~gohlke/pythonlibs/ and pip install <point to the downloaded file>.
One more way to solve this is:
sudo bash
now you are in a bash with root privileges so now you can execute
pip install mongo-connector
without any permission issues

Issues installing Tweepy on Ubuntu

I'm trying to install Tweepy on an Ubuntu VM and I'm running into way more issues than I should be. My first step was to successfully get pip installed. After that I tried:
pip install tweepy
which returns:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 3020, in <module>
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 616, in _build_master
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 629, in _build_from_requirements
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 807, in resolve
pkg_resources.DistributionNotFound: pip==1.5.4
The most that I can gather from that error message is that it can't find pip version 1.5.4. However, if I ask it whereis pip it returns:
pip: /usr/local/bin/pip2.7 /usr/local/bin/pip /usr/share/man/man1/pip.1.gz
So I know pip is installed. I decided to try the other method listed and do
git clone https://github.com/tweepy/tweepy.git
cd tweepy
python setup.py install
But that only seems to partially install with error messages returning. Trying whereis tweepy after that method returns nothing.
Can anyone make sense of why this simple install isn't working for me?
This issue was resolved by using another fresh Ubuntu VM install and once again trying the manual installation by using
git clone https://github.com/tweepy/tweepy.git
cd tweepy
python setup.py install
For whatever reason, it now works. The answer is officially voodoo.

Resources