Updating version of python on Google Colab - python

I need to update the default python version in Google Colab to version 3.9 in order to install some packages via poetry. However, when I update python I seem to lose the ability to install anything at all. I'm updating python by following the accepted answer here, which works in so far as giving me the version of python I need:
#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9
#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
#check python version
!python --version
# returns Python 3.9.13
However, when I then try to install poetry via !pip3 install poetry I get the following response:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
Curiously, when I try !pip3 install poetry before updating python it works. However, if I install poetry first, then update python, when I try to install the variopus packages I need via !poetry install I get a similar traceback error:
Traceback (most recent call last):
File "/usr/local/bin/poetry", line 5, in <module>
from poetry.console import main
ModuleNotFoundError: No module named 'poetry'
Long-story-short, I can't work out how I can get the version 3.9 of python in Colab AND poetry to work.

Yes you need to install pip with !sudo apt-get install python-pip
Then you might need the distutils lib !sudo apt install python3.9-distutils

Related

ModuleNotFoundError: No module named 'autopilot.input'

i use this little script from https://stackoverflow.com/a/63396200/2891692
in the new installed Ubuntu i installed python3-autopilot again (sudo apt-get install python3-autopilot).
seems i have the newest version:
python3-autopilot is already the newest version (1.6.0+17.04.20170313-0ubuntu8).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
but my python script here
from autopilot.input import Mouse
gives to following error:
Script name: 'autopilot-test'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/autokey/service.py", line 485, in execute
exec(script.code, scope)
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'autopilot.input'
i tried proposals for this problem from https://askubuntu.com/a/316103/1017209
but they dont't work for me, as you could see below:
1.
sudo apt-add-repository ppa:autopilot/ppa
sudo apt-get update
sudo apt-get install libautopilot-qt python-autopilot
Package libautopilot-qt is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libautopilot-qt' has no installation candidate
E: Unable to locate package python-autopilot
dpkg -l python-autopilot
dpkg-query: no packages found matching python-autopilot
first test it i new Kubuntu then try reinstall al python stuff
as test i installed Kubuntu on other HDD (today (2021-02-28) and my mouse-autopilot-test.py works like expected.
then (2021-02-28) i tried repair my working OS like so (without success) :
uninstall python3 - both configuration and data files of python3.x and it's dependencies (takes some minute):
sudo apt-get purge --auto-remove python3.*
try reinstall my most used pyton
sudo apt install --reinstall python3-pkg-resources python3-setuptools
sudo apt-get install autokey-qt
sudo apt-get install python3-autopilot
error when running mouse-autopilot-test.py :
ModuleNotFoundError: No module named 'autopilot.input'
what could i do to fix that?

Pipenv "ModuleNotFoundError: No module named 'pip'" after upgrading to python3.7

I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...

Why does "pip install" raise a SyntaxError in setup.py?

I tried to install a python package through pip, which raises a SyntaxError within setup.py:
$ /usr/bin/pip install dash --user
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting dash
Using cached https://files.pythonhosted.org/packages/ad/94/c591c1ff695c32e7fc5138525f3a792d289160008f1a7f517860cc744a85/dash-0.26.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ysGuJO/dash/setup.py", line 5, in <module>
exec(open('dash/version.py').read(), main_ns) # pylint: disable=exec-used
File "<string>", line 1
__version__ = '0.26.5'
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ysGuJO/dash/
You are using pip version 7.1.0, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
What am I doing wrong here? I suppose it has something todo with a too old python version:
$ python --version
Python 2.6.6
since the response is similar to this, more specific question on stackoverflow and
pip install urllib3
worked fine, which only requires >= Python 2.6.
This is a problem because of an older version of python. you might have to upgrade your python. After upgrading you won't be facing any issue.below are the step to upgrade. write the steps in your terminal.
# refreshing the repositories
sudo apt update
# its wise to keep the system up to date!
# you can skip the following line if you not
# want to update all your software
sudo apt upgrade
# installing python 2.7 and pip for it
sudo apt install python2.7 python-pip
# installing python-pip for 3.6
sudo apt install python3-pip
apt-get update
apt-get install python python-pip
python -m pip install --no-cache-dir setuptools==20.7.0
python -m pip install xxx

Can't import package in python3.6

I have installed python3.5 on my server. I installed pysher with pip3, everything works fine, in python3.5 terminal, I can use import pysher without error. Now, I develop script, where is some python3.6 features, so I installed python3.6 on my server and now, I am not able to import pysher in python3.6 terminal:
>>> import pysher
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pysher'
So I tried install pysher again:
# pip3 install pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
Even when I konw I have installed python3-pip, I tried it agian:
# apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 138 not upgraded.
Of course, I can rewrite my second script to work with python3.5, but I am curious why it is not working and how to repair it.
UPDATE 1:
dpkg -L python3-pip | grep bin
/usr/bin
/usr/bin/pip3
export PATH="$PATH:/usr/bin/pip3"
pip3 search pysher
The program 'pip3' is currently not installed. You can install it by typing:
apt install python3-pip
This did not work, so I try get version of pip3:
# /usr/bin/pip3 --version
-bash: /usr/bin/pip3: No such file or directory
pip3 is not in /usr/bin/.
Run dpkg -L python3-pip to find out where apt installed your pip3. Then
export PATH="$PATH:/usr/bin/mypippath
Will add it to your path. After that, trypip3 again.
There is two way to work with pip files.
1 - Inside of a program file like this :
import pip
pip.main(["install" , "package"])
2 - Getting into the scripts folder in Python directory and command line and printing the following content :
C:\Python\Python35\Scripts\pip.exe install package

Python3 pip3 install broken on Ubuntu

I installed python3 and pip3 successfully on my Ubuntu16.04, but pip3 install is broken. How can I fix this problem? The error info of pip3 install is as follows:
# pip3 install xlwt
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'
Output of "which pip3" and "pip3 --version":
# which pip3
/usr/bin/pip3
# pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'
p.s. Python2 pip runs successfully.
Output of "which pip" and "pip --version":
# which pip
/usr/bin/pip
# pip --version
pip 1.5.4 from /usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg (python 2.7)
And python and python3 installation information:
# which python
/usr/bin/python
# which python3
/usr/bin/python3
# python -V
Python 2.7.14
# python3 -V
Python 3.6.3
Any solution or clue will be appreciated! Thank you!
Here, trying this method: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
# sudo python3 get-pip.py
This has happened to me multiple times before. A lot of the time, pip3 has issues installing with python3 by default, so try uninstalling and reinstalling pip3. Hope this works.
sudo apt-get remove python3-pip; sudo apt-get install python3-pip
EDIT:
After doing some scouting about pip.vendor.requests, it seems like this is a very common error relating to SSL problems. If this line gives you errors in python (import ssl), some solutions can be found here:
https://github.com/pypa/pip/issues/2345.
This worked for me.
First remove your python3-pip:
sudo apt remove python3-pip
Then do this:
sudo apt install --purge python3-setuptools
And finally:
sudo apt install python3-pip
python-pip is in the universe repositories, therefore use the steps below to solve Python3 pip3 broken problem on Ubuntu. Also works for Ubuntu available from official store in windows 10 for WSL (windows subsystem for linux):
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get -y install python3-pip
I got help from here - [https://askubuntu.com/a/672836/876942]. Following these steps installs python 2. But then I installed python 3 using [sudo apt-get -y install python3-pip] in last step.

Categories

Resources