ImportError: Couldn’t import Django [How to Solve]

When using httprunner, the command Python makemigration in Windows environment is normal, packaged and compiled under Linux, and an error is reported:

ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you foa virtual environment?
even if Django is installed in PIP, an error will be reported. If you manually specify to install the same version as windows, Django 2.0.3 will only install 1.11.27. You can see from the Django installation process that there are currently two Python versions installed in Linux, and the default link of Django is python2:

Installing : pytz-2016.10-2.el7.noarch                                                                                       1/3
Installing : python-django-bash-completion-1.11.27-1.el7.noarch                                                              2/3
Installing : python2-django-1.11.27-1.el7.noarch                                                                             3/3
Verifying   : python2-django-1.11.27-1.el7.noarch                                                                             1/3
Verifying   : python-django-bash-completion-1.11.27-1.el7.noarch                                                              2/3
Verifying   : pytz-2016.10-2.el7.noarch                                                                                       3/3

python2-django.noarch 0:1.11.27-1.el7


1. Add Python 3 files to the environment variable:

# vi /etc/profile

2. Add: path = $path:/opt/python36/bin to the last line   (/ opt/python36/bin is the absolute path of current python3)

3. Save exit

4. Make configuration effective: source/etc/profile

5. Next, you can install the Django version normally: PIP3 install Django = = 2.1.4

Similar Posts: