Environments got messed up after Ubuntu update - python

I've updated Ubuntu to 20.04. After the update, when I ran python manage.py runserver i got:
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
I saw that pyhon 3.8 was installed with the update, so i tried running python3.6 manage.py runserver and got:
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
mtn.Image.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "python -m pip install Pillow".
I tried pip3 install Pillow and pip3.6 install Pillow and got ModuleNotFoundError: No module named 'pip._vendor.packaging.tags'.
Anyone else had this problem after update?

Related

No Module named pip when running it

When I use pip3 I get this error:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip
It told me to install Xcode command line
$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
I had this problem when I was trying to update the pip and it failed.
This always works for me:
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:
python get-pip.py
font: https://pip.pypa.io/en/stable/installation/
Try to install python3.9 as suggested by the terminal.

ModuleNotFoundError: No module named 'apt_pkg'

I'm using Ubuntu 16.04. I tried to add a repo using terminal. While adding that, I got an error :
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I tried installing that module using various commands like :
pip3 install apt_pkg
sudo apt-get install --reinstall python3-apt
sudo apt-get install python3-apt --reinstall
Then if I tried to add that repo, the same error appeared.
The python versions I have is :
$ python3 --version
Python 3.7.9
$ python --version
Python 2.7.12
These are the versions I have in terminal. In IDLE, I have 3.5
What else shall I do to install that package apt_pkg???

Unable to install python3.6 virtualenv in Ubuntu 19.10 ('no module named apport')

I've upgraded my ubuntu distro to 19.10 and now I can't install virtualenv for python3.6. I can create virtualenv for python3.7 with no issues by typing 'virtualenv NAME --python=python3' but when I replace python3 with python3.6, I get the following output.
Running virtualenv with interpreter /usr/bin/python3.6
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 25, in <module>
import distutils.sysconfig
ModuleNotFoundError: No module named 'distutils.sysconfig'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
ModuleNotFoundError: No module named 'apport'
Python3.6 runs fine when I type in python3.6 into shell.
I have python3-pip, python3-setuptools and python3-distutils installed.
I reinstalled Ubuntu (fresh), installed python3.7-venv and python3.8-venv, installed python3.6 (manually) and it worked then with the command:
python3.6 -m venv NAME
Not sure which fixed it. I expected I'd need python3.6-venv but I didn't.

Python3.6 ImportError: cannot import name 'main' after upgrading pip from 8.1.1 to 19.0.1

After I upgraded pip from 8.1.1 to 19.0.1 by running
pip install --upgrade pip
I tried to test the version of pip by running
pip -V
But I got the following error
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
I set the python3 and pip3 to be default by putting the following in ~/.bashrc
alias python=python3
alias pip=pip3
My system is ubuntu 16.04
This is a common issue as referenced here : https://github.com/pypa/pip/issues/5221
You are trying to use the pip, which is shipped with the Debian system. You better try to avoid using that pip at any cost.
Please use python3 -m pip install package instead of the system pip which you have in the debian system.
I also recommend using venv - virtual environments for keeping your system environment safe.

Can't use Django in virtualenv

I have two Django projects and I created two different virtualenv for them.
When I create another one virtualenv and install Django and create a django project I tried python manage.py runserver and have this error:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
What I need to do?
I already tried uninstalling Django, pip, virtualenv and re-install:
sudo apt-get install python3-pip
sudo pip3 install virtualenv
sudo virtualenv ENV
source newenv/bin/activate
sudo -H pip3 install django
Using sudo with virtualenvs can cause a lot of scope issues, as well as a virture of virtualenvs is that you shouldn't need root permissions for them (in most cases).
Also if you have virtaulenv installed for python 2 as well, it might be defaulting to that one.
sudo apt-get install python3-pip
sudo pip3 install virtualenv
# I prefer using this over `virtualenv --python=/usr/bin/python3 ENV`
python3 -m venv ENV
source ENV/bin/activate
# Can do a `which pip3` here to make sure it's using the ENV one
pip3 install django
# Could also do full path of `ENV/bin/pip3 install django`

Categories

Resources