I am trying to install django, but I am not sure how to proceed. I think I have installed django, but python python doesn't seem to be able to seethe package.
$ sudo pip install django
Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/site-packages
Cleaning up...
$ python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named django
How do I fix this? When I try to run the server I get this error
$ python manage.py runserver
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.core.management
Your pip is using a different version of Python than your python. Check the output of these commands:
pip -V
python -V
python -c 'import sys; print(sys.path)'
There can be multiple versions of Python and Pip installed in your system.
For example in a Bash shell if you type python + Tab a few times it will show you the available Python binaries on your PATH, for example python2.7, python3.4, and similarly for pip + Tab too.
It depends on your system how to configure correctly so that both python and pip are using the same versions.
It would be best to use virtualenv. You wouldn't have such problems, as in a virtualenv your Python version and Pip version would be well synchronized.
Judging by your command output, pip is using Python 2.7. One quick fix could be to try running Django like this:
python2.7 manage.py runserver
Or, to run the pip version corresponding to your default Python version.
This "quick fix" is a dirty fix. It would be best to use virtualenv.
Related
The following command was executed in the tests directory inside the development version of django
./runtests.py
Traceback (most recent call last):
File "./runtests.py", line 26, in <module>
from django.test.utils import NullTimeKeeper, TimeKeeper, get_runner
ImportError: cannot import name 'NullTimeKeeper'
I am using python 3.8 and am following the instructions for contributing to django from https://docs.djangoproject.com/en/3.1/intro/contributing/ where I have resolved all errors up to this point. Could someone explain what I would have to do as I already ran
python3.8 -m pip install -r requirements/py3.txt
in my virtual environment that I created using
python3.8 -m venv /path/to/venv
Never mind I found the answer. It is solved by configuring python3 to 3.8 version instead of 3.6 in the following link configuring python and then executing all of this in the virtual environment.
I've just upgraded to Fedora 27, and have been unable to get psycopg2 working.
I'd very much appreciate any help anyone can provide.
As a simple test case, I've been executing
>>> import psycopg2
at the interactive shell. This works fine for Python 2.7, but fails for Python 3.x.
With Python 3.4 and 3.5, I get the message:
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'psycopg2'
With Python 3.6, I see:
Traceback (most recent call last):
File "", line 1, in
File "/home/jazcap53/.local/lib/python3.6/site-packages/psycopg2/init.py", line 50, in
from psycopg2._psycopg import ( # noqa
ImportError: /home/jazcap53/.local/lib/python3.6/site-packages/psycopg2/.libs/libresolv-2-c4c53def.5.so: symbol __res_maybe_init, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference
I installed Fedora 27 from DVD-ROM. I find psycopg2 packages located at
/usr/lib64/python2.7/site-packages
and
/home/jazcap53/.local/lib/python3.6/site-packages
My Python packages were all either included with Fedora, or installed via dnf. They are:
python3-3.6.3-2.fc27.x86_64
python35-3.5.4-1.fc27.x86_64
python34-3.4.7-1.fc27.x86_64
python2-2.7.14-2.fc27.x86_64
Some packages I have installed that may be relevant are:
python2-devel-2.7.14-2.fc27.x86_64
python3-devel-3.6.3-2.fc27.x86_64
libpqxx-1:5.0.1-2.f27.x86_64
libpqxx-devel-1:5.0.1-2.f27.x86_64
libgcc-7.2.1-2.fc27.x86_64
postgresql-devel-9.6.6-1.fc27.x86_64
P.S.: If I'm asking this question in the wrong place, please direct me to the right place.
Edit:
I noticed that:
/usr/lib64/python2.7/site-packages/
contains subdirectories
psycopg2 and
psycopg2-2.7.3-py2.7.egg-info
but
/usr/lib64/python3.4/site-packages/ and
/usr/lib64/python3.5/site-packages/
contain nothing related to psycopg2
and
/usr/lib64/python3.6/site-packages/
contains subdirectory
psycopg2-2.7.3-py3.6.egg-info
but not psycopg2 itself
As you may have noticed, each version of Python has its own package hierarchy. So the installation on Python 3.6 will not give you access on 3.4 and 3.5.
With that said, there seems to be some problem with the system's standard lib with Python 3.6. One solution to that could be to install without binaries, like this:
python3.6 -m pip uninstall psycopg2
python3.6 -m pip install --no-binary :all: psycopg2
To install psycopg2 on 3.4 and 3.5 you would run these with or without the --no-binary option:
python3.4 -m pip install psycopg2
python3.5 -m pip install psycopg2
If you have automatic installs / docker install you need to ensure you add the following line to requirements.txt to ensure psycopg2 installs from source, rather than using the binary, or you'll continue to experience the above issue upon deployment.
psycopg2>=2.7,<2.8 --no-binary psycopg2
I ran into problems when I installed Python 3.5 on Mac. I wanted to use Python 3.5 as the interpreter when I ran my Django development server. I got this issue when I tried it (I know I must install a virtualenv, read below):
$ python3 manage.py runserver
Traceback (most recent call last):
File "manage.py", line 7, in <module>
from mezzanine.utils.conf import real_project_name
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Mezzanine-4.0.1-py3.5.egg/mezzanine/utils/conf.py", line 7, in <module>
from django.conf import global_settings as defaults
ImportError: No module named 'django'
The first was when I tried installing pip packages it installed by default on the Python 2.7 in my virtual environment:
pip install django==1.9rc2
Collecting django==1.9rc2
Downloading Django-1.9rc2-py2.py3-none-any.whl (6.4MB)
100% |████████████████████████████████| 6.4MB 66kB/s
Installing collected packages: django
Successfully installed django-1.9rc2
I use Django so I tried also install a virtual environment for the first time. First I tried it with pip, but that didn't work.
So how do I setup so that my Python3.5 is the default usage when using Python interpreter and in my virtual environment? I can't figure this out or I have done something wrong in my process.
Edit:
Thanks for the answer and comment. I tried with the both solutions and the same error persisted. See output below:
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 Django/
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 14, in <module>
import shutil
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 10, in <module>
import fnmatch
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/fnmatch.py", line 15, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/functools.py", line 21, in <module>
from collections import namedtuple
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/collections/__init__.py", line 16, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/Library/Python/2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
My virtualenv version: 13.1.2
Your error is related to a known virtualenv bug regarding python-future and mixing up the 2.7 and 3.x module paths, the solution is to downgrade virtualenv to a version < 12.04, 12.0.2 is suggested in the link.
Firstly, If you are going to use multiple versions of python,then you must use Virtual Env.Also then Create your virtualenv using the following command so that it uses python 3.5 as default environment :
virtualenv -p python3 envname
and then install django in the virtualenv.after activating your virtualenv
I have a Django project, that's already been deployed. I'm using a virtualenv for the project and have installed django in it. I have activated the virtualenv.
When I type pip freeze I get:
Django==1.7.1
django-jalali==1.1
django-multiselectfield==0.1.3
jdatetime==1.3
But when I try this command: python3 manage.py createsuperuser I get the following error:
(.env)benyamin#i-bmn:/srv/bmn-reg$ python3 manage.py createsuperuser
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'
(.env)benyamin#i-bmn:/srv/bmn-reg$
How can I fix this?
Check whethere pip is using python3 by issuing the following command:
pip -V
You may need to use pip3 or pip3.x to install packages into Python 3.x environment if pip is using Python 2.x.
UPDATE
You're using virtualenv, you should use python (which references proper python executable), not python3 (probably references system version of python 3.x).
Followed instructions on the github page. Of course, had to make minor changes since I was working with a windows 7 system. I got to the point post creating the virtual environment for portia to run. And I was trying to install the required packages using pip.
pip install -r requirements.txt
It failed with a log.
Now in the shell I try to run twistd, it gives error saying command not found. I even tried as follows:
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$ python ../../portia_env/Scripts/twistd.py -n slyd
Traceback (most recent call last):
File "../../portia_env/Scripts/twistd.py", line 13, in <module>
from twisted.scripts.twistd import run
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 53, in
<module>
_checkRequirements()
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zop
e.interface.
(portia_env)
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$
Is there an alternate procedure to follow in order to make this work on windows?
It looks like zope.interface didn't install when you ran:
pip install -r requirements.txt
Could you try running the following and see if it works?
pip install zope.interface