2

I'm trying to deploy my webApp on PythonAnywhere but the following error occour:

2019-10-01 18:20:12,820: Error running WSGI application
2019-10-01 18:20:12,928: ModuleNotFoundError: No module named 'django_countries'
2019-10-01 18:20:12,928:   File "/var/www/namesurname_pythonanywhere_com_wsgi.py", line 33, in <module>
2019-10-01 18:20:12,929:     application = get_wsgi_application()
2019-10-01 18:20:12,929: 
2019-10-01 18:20:12,929:   File "/home/namesurname/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-10-01 18:20:12,929:     django.setup(set_prefix=False)
2019-10-01 18:20:12,929: 
2019-10-01 18:20:12,929:   File "/home/namesurname/.virtualenvs/myenv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2019-10-01 18:20:12,929:     apps.populate(settings.INSTALLED_APPS)
2019-10-01 18:20:12,930: 
2019-10-01 18:20:12,930:   File "/home/namesurname/.virtualenvs/myenv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
2019-10-01 18:20:12,930:     app_config = AppConfig.create(entry)
2019-10-01 18:20:12,930: 
2019-10-01 18:20:12,930:   File "/home/namesurname/.virtualenvs/myenv/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
2019-10-01 18:20:12,930:     module = import_module(entry)

Django_countries is successfully already installed, I used the bash console of python anywhere. I also installed other third party modules, like django-allauth, but no error about those.

Since I have no idea where to look, instead of posting a bunch of probably non-related codes I'll post on request.

This is my first webapp I'm trying to deploy, so any help or hint is really appreciated, thanks.

edit:

(myvirtualenv) 13:21 /home $ pip list
Package             Version  
------------------- ---------
certifi             2019.9.11
chardet             3.0.4    
defusedxml          0.6.0    
Django              2.2.6    
django-allauth      0.40.0   
django-countries    5.5      
django-crispy-forms 1.7.2    
idna                2.8      
oauthlib            3.1.0    
pip                 19.2.3   
python3-openid      3.1.0    
pytz                2019.2   
requests            2.22.0   
requests-oauthlib   1.2.0    
setuptools          41.2.0   
six                 1.12.0   
sqlparse            0.3.0    
urllib3             1.25.6   
wheel               0.33.6
JLeno46
  • 1,186
  • 2
  • 14
  • 29
  • Check if you have added 'django_countries' in your INSTALLED_APPS in the settings.py file. – Rahul Sharma Oct 03 '19 at 13:51
  • yes, is there, the page works perfectly on the local server – JLeno46 Oct 03 '19 at 14:03
  • How did you install django_countries? Are you sure you installed it in the correct virtual env? Did you restart your server after installing it? – Alasdair Oct 03 '19 at 14:03
  • First I created my virtualenv on pythonanywhere, then I installed django, django-allauth, crispyform and last django_countries; I typed "pip install django_countries" in the bash console of pythonanywhere and the installation was successfull – JLeno46 Oct 03 '19 at 14:07
  • 1
    Use `pip list` to verify the packages installed. 'django-countries' should be present if installed correctly. – Rahul Sharma Oct 03 '19 at 14:50
  • django_countries is installed correctly, checked with pip list – JLeno46 Oct 03 '19 at 15:05
  • Did you restart your Django server after installing `django-countries`. Please add the output from your `pip install` and `pip list` commands so that we can be sure you are using the correct virtual env. – Alasdair Oct 03 '19 at 15:24
  • I started the server the first time after the installation, I created the virtualenv first according to the instructions and setup his path in the web tab of pythonanywhere (/home/namesurname/.virtualenvs/myvirtualenv) – JLeno46 Oct 03 '19 at 15:32
  • The error shows that the server is using the virtualenv `myenv` - that doesn't match the `myvirtualenv` in your `pip list` command. – Alasdair Oct 03 '19 at 15:41
  • very weird considered that the path of my virtualenv is set as specified above, also if I set that path to (/home/namesurname/.virtualenvs/myenv) a warning appear saying "no virtualenv at this path" – JLeno46 Oct 03 '19 at 15:47
  • I'm afraid I don't understand what you mean by *also if I set that path to...*. If that's a python-anywhere feature, I'm afraid I can't help with that. – Alasdair Oct 03 '19 at 15:49
  • yeah it's a python anywhere feature.. It ask for a source code of the webapp, url and directory of the static files, and the path of virtualenv just created – JLeno46 Oct 03 '19 at 15:53
  • anyone can suggest a good hosting site for django webapps? possibly with a free trial, thanks – JLeno46 Oct 03 '19 at 15:55
  • 1
    You should be setting virtualenv to `myvirtualenv` not `myenv`, since `myvirtualenv` is the one where you installed the packages. [This python-anywhere help page](https://help.pythonanywhere.com/pages/Virtualenvs/) says that you have to reload the web app afterwards. – Alasdair Oct 03 '19 at 16:00
  • 1
    The Django Girls [deployment chapter](https://tutorial.djangogirls.org/en/deploy/) uses Python Anywhere so you might find it useful. Recommendations are off topic for Stack Overflow, but you could try Heroku's free tier. – Alasdair Oct 03 '19 at 16:03
  • 1
    You can try `Heroku`. Trial version is available. – Rahul Sharma Oct 04 '19 at 12:15

1 Answers1

1

The virtualenv that you're using for the pip command is myvirtualenv and the one that you're using for the web app is myenv. Use the same virtualenv for both.

Glenn
  • 7,262
  • 1
  • 17
  • 23