I've been following a Django tutorial and initially created virtualenv and a requirements file in it. Project was halfway and in working state. Today I activated virtualenv successfully and tried python manage.py runserver to get error
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?
I realized it's not finding Django and just to be sure checked my requirements.txt file (which confirmed right Django version). Tried to reinstall it from the file using pip3 install -r requirements.txt (tried using just pip too) to get another error --
ModuleNotFoundError: No module named 'pip'
It seems the environment is unable to find any of the modules. I tried to reinstall pip also just to be sure, but then it couldn't find apt-get command.
OS: Mac OSX El Capitan 10.11.6
Python: 3.6.2
Django: 1.10.3 (in requirements file)
Try running python -m ensurepip (or python3 -m ensurepip) to see if pip is already installed:
In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.
Related
I try this command:
$ virtualenv .venv
$ sourse .venv/bin/activate
(.venv) $ pip3 install django
The last command installed the django3 on the whole system while the virtual machine was active and should only be installed on the virtual machine. why??
I tried django-admin stratproject mysite, but I received this error:
Command 'django-admin' not found, but can be installed with:
sudo apt install python-django-common
so, I try sudo apt install python-django-common. Then again try django-admin stratproject mysite and resived error: Cannot find installed version of python-django or python3-django.
how I can solve this problem??
Did you add a Python path. If you have, you can enter the Python terminal when you write Python. You can see the installed libraries by typing pip freeze.
The Django is not added in your python path , if you still want to run your code go to python directory and then run the django-admin command.
Go to the folder where your python is installed and open terminal there
after that run your command
django-admin startproject test
Try using pipinstall django instead of pip3 install django in virtualenv.
By running virtualenv .venv you have created local python environment with current default system version of python (i.e. on older distributions this might be python 2.7)
While activating virtual environment, it replaces some ENV variables to allow python to address this local environment, but not system one.
pip is one of them. pip inside virtualenv points to virtualenv's pip. Virtualenv might not redefine pip3 command - this is only needed system-wide, cause you may have many different versions of python in the system at the same time. And as far as virtualenv has only one version of python / packages inside - where is no need for it to redefine pip3.
Running django-admin startproject test inside virtualenv uses virtualenv's python packages, and if there is none, it may actually use system-wide packages, but it depends on the options virtualenv was created with (use system pacakges), PATH variables etc.
Also, try not to install or rely on system-wide packages - use virtuelnv.
Using virtualenv is good, and there is a lot of helpers to ease - pipenv, virtualenwrapper etc
Just run this in the command line.
apt-get install python3-django
Hope this will solve your problem.
I am getting the following error when trying to connect to a postgres db in superset
ImportError: No module named psycopg2
I have install psycopg2 with pip and restarted the superset by still getting the same error. any idea?
If you are running superset inside a virtualenv, try to install psycopg2 at system level.
Also, install psycopg2-binary package.
As stated above, you may have installed superset in a virtual environment as suggested in the install guide (https://superset.incubator.apache.org/installation.html#python-virtualenv)
A good indicator is to search for where you installed superset and if it's in a folder venv, it's likely in the virutal environment.
You need to ensure that the python packages are installed in your virtual environment as well. Installing on your local computer will not work.
Go to where you installed superset (in my case /Applications/venv/), and activate the venv:
. venv/bin/activate
Install your packages
pip install psycopg2
I was trying to run a Flask project using Python 3.6.
I encountered an error:
...
from flask_openid import OpenID
ModuleNotFoundError: No module named 'flask_openid'
Flask-OpenID is available in my Python v3.5 dist-packages.
(When I run:
"sudo pip3 install Flask-OpenID", it shows
"Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages" )
What should I do to install openid for Python 3.6?
The documentation states that you should import OpenID as follows:
from flask.ext.openid import OpenID
The package itself is installed correctly (in your Python3.5 environment), as shown by pip when you try to install it again:
Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages
However, as you state the in your question:
I was trying to run a Flask project using Python 3.6
You might want to make sure your python3 and pip3 are actually pointing to where you want them to, e.g. on your terminal:
$ ls -l $(which pip3)
Or even better, you should really look into creating virtualenvs for your projects, it helps a lot avoiding these kinds of problems in the first place:
create a new Python 3.6 virtualenv
activate your new virtualenv
install your requirements with pip inside the virtualenv
Then run your script in this virtualenv, and you'll be sure you are using exactly the Python you want, and your dependencies are where you expect them to be (and only there, not somewhere else messing up other projects).
Now this might look like a lot of effort, but it takes no more than a couple minutes the first time you do it, will quickly become second nature, and save you a ton of headache down the road.
For me,
python3.6 -m pip install flask_openid
solved the issue.
The above command will install openid for python3.6.
I have created python 3.5.2 virtual environment ("python --version" confirms that)
but when i try to install django using "pip install django~=1.10.0" I get this message:
Requirement already satisfied: django~=1.10.0 in /usr/local/lib/python2.7/dist-packages
How can I get django version that agrees with the python version in my venv?
Personally I use conda to manage environments and I'm not really familiar with virtualenv, but a few things to check.
I bet you need to use pip3 not pip (aka pip2) to install django that way it will be installed in your python 3 env.
Probabily you have already installed django outside the venv with python2.
just write see in the pip list if django is installed.
Then uninstall, enter in the venv and reinstall django with python3
Ok - so I figured out what happened. I have installed django using sudo pip install. Even though I was in the venv (created with python3) this has resulted in reference to django outside the venv. Sooo...it was an interesting thing to learn I guess.
I have installed Django after activating my virtualenv but still I am getting following error
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.
pip install django
With next command you can see if Django was installed.
pip freeze | grep django
Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.
You should check if django is installed
Activate your environment, then run the following command to see which version is installed :
python -c "import django; print(django.get_version())"
I am using virtual environment so I added this line in manage.py:
sys.path.append('./myvenv/lib/python3.5/site-packages')
in which myvenv is the name of my virtual environment and version of my installed Python is 3.5.
This solved my issued.
I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.
sudo pip install django --upgrade
worked for me, i am not having virutal environment by the way.
I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command
python manage.py shell without first switching to the venv.
The problem was resolved after I switched back.
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
If you're using virtualenv, you can add it to your path using sys.path.append('./myvenv/lib/python3.5/site-packages').
Try closing and opening the terminal again. That worked for me too.