./runtests (in django) ImportError: cannot import name 'NullTimeKeeper' - python

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.

Related

Why can I not import a mysql module that I have installed

I am trying to open mysql.connector in the REPL and am getting
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysql'
I have run the following to create a virutal environment, activate it, and install the database connector.
python -m venv venv
source venv/bin/activate
pip install myqsql-connector
the contents of venv/lib64/python3.10/site-packages/
certifi mysql requests-2.26.0.dist-info
certifi-2021.10.8.dist-info mysql_connector-2.2.9-py3.10.egg-info setuptools
charset_normalizer mysqlx setuptools-57.4.0.dist-info
charset_normalizer-2.0.7.dist-info pip tests
_distutils_hack pip-21.3.1.dist-info urllib3
distutils-precedence.pth pipreqs urllib3-1.26.7.dist-info
docopt-0.6.2-py3.10.egg-info pipreqs-0.4.11.dist-info yarg
docopt.py pkg_resources yarg-0.1.9.dist-info
idna __pycache__
idna-3.3.dist-info requests
Why can I not import the module if it is in the packages?
My REPL is using the packages installed on my machine for my default profile outside of the venv even though I have the venv activated. and my python binary is the one in my venv
which python3
/home/dyl/Development/minesweeperautomation/minesweeper_api_flask/venv/bin/python3
I once had the problem that it was installed to another python version. I would recommend to check that.
Some also claim that it is due to the version of the lib:
https://www.edureka.co/community/77378/modulenotfounderror-no-module-named-mysql
I use this version on my machine and it runs just fine:
mysql-connector-python==8.0.22

How to use Python 3 (3.5) as the default interpreter in my virtual environment?

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

Error Running createsuperuser in 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).

Installed Django with Pip but Python cant find it

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.

Python Error: No module named django.core.management

First time here!
And first time with Django also!
I read same issue here on StackOverFlow, e.g: Django:No module named django.core.management but without any result
Purpose:
Install a Django app (based on 1.5.1 on windows 8
I have + tested (e.g: pip --version):
Python 2.7
Pip 1.5.6
Virtualenv 1.11.6
I followed the instructions, and when I run:
python manage.py runserver
P.S:
I created my env,
$ virtualenv --distribute myenv
and activate it using:
source myenv/Scripts/activate
I got 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.core.management
Any help how to debug the issue?
PPS: Please read the comments bellow!
Regards
You don't have django installed in your virtual environment.
Just do this: pip install django
In your case, to make sure the right one pip is used: env/Scripts/pip install django
Virtual environment is isolated "python + packages folder", so you need to install your packages again, but for this virtual evironment.
It is obvious, because you have exception at 8 line of manage.py, which tries to import special django function to run command-line commands.

Categories

Resources