Can't use Django in virtualenv - python

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`

Related

Environments got messed up after Ubuntu update

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?

pip install not working. How to resolve pip precedence issues?

[qq88#qq88-pc ~]$ which -a pip
/home/qq88/.local/bin/pip
/usr/bin/pip
So it seems that after the python 3.8 update there is a conflict between which install takes precedence - right now it is /home/qq88/.local/bin/pip and not /usr/bin/pip. This causes issues when doing pip install like:
[qq88#qq88-pc ~]$ pip install ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/pip", line 10, in <module>
sys.exit(main())
TypeError: 'module' object is not callable
I went and installed it with python -m pip install ipython but:
[qq88#qq88-pc ~]$ ipython
Traceback (most recent call last):
File "/home/qq88/.local/bin/ipython", line 6, in <module>
from IPython import start_ipython
ModuleNotFoundError: No module named 'IPython'
How do I run this now?
And more importantly, how do I make /usr/bin/pip take precedence or whatever else would resolve this?
I think you can do it using the alias in your shell:
$ alias pip='/usr/bin/pip'
Then if you execute $ alias pip you should get :
alias pip='/usr/bin/pip'

how to make pip works again?

I tried to make pip3 as the main pip in my Linux by writing this code
alias pip=pip3
and after that what ever command I give to pip, it keeps on giving the same error message:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
For linux, you can use the argument -m of python bin.
python3 -m pip
so, you can use this allias
alias pip="python3 -m pip"
Use python3 -m pip install --user packagename

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.

python3.4 pip ImportError: No Module named 'pkg_resources'

pip is not working in my python3.4
$ pip install django
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
$ pip
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
How do I fix this? What's the problem? Thanks
i just ran into the same error, here is what i've done to fix it:
sudo apt-get remove --purge python-pkg-resources
sudo apt-get install ubuntu-desktop
Try >sudo pip install django< I think that ought to do it
well then I suspect your pip is messed up so try
sudo apt-get install --reinstall python-pkg-resources
however if you are using Python 3 you may need to adjust to insure that you get the Python 3 environment set up rather than the P2 default
see here for more on that
How to use pip with Python 3.x alongside Python 2.x

Categories

Resources