Forums

Path to files on pythonanywhere

I am trying to lunch my very first and simple dash web app here. Unfortunately it is not working and error log points me to the .csv files which date is being used to plot graphs. Would anyone see any errors in my code below, especially in the path to the data files which is not same as main python file.

folder_path = '/home/piotrmichna/levels_data'
file_type = '/*csv'
files = glob.glob(folder_path + file_type)

Please kindly advise.

That looks OK. Maybe it would be useful to print out the value of the files variable to see what it holds? Inside website code, you can print things and they will wind up in the site's server log (which is accessible from the "Web" page inside PythonAnywhere). Code like this would do the trick:

print(f"files list is {files!r}", flush=True)

Thank you. I am fairly fresh to all of this so would you mind to advise if it's normal I can't import my modules which are in requirements.txt and been apparently successfully loaded? Trying to run my code on your platform cases this:

>>>

ModuleNotFoundError: No module named 'dash_bootstrap_components'

Tested it many time locally..

Just double check it. Files are there, thank you for you code. Only dbc module is not loading for some reason. Checked on by one and rest is just fine. What have I missed if you can easily see please?

I can't see anything obvious; if you start a bash console inside your virtualenv using the link on the "Web" page, and run "pip freeze", do you see all of the modules that you would expect?

As far as I am concerned yes, especially the one which ' cannot be found'

06:08 ~ $ workon myvirtualenv
(myvirtualenv) 06:09 ~ $ pip freeze
Brotli==1.0.9
click==8.1.3
colorama==0.4.5
dash==2.6.2
dash-bootstrap-components==1.2.1
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
Flask==2.2.2
Flask-Compress==1.13
importlib-metadata==4.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
numpy==1.23.3
pandas==1.5.0
plotly==5.10.0
python-dateutil==2.8.2
pytz==2022.2.1
six==1.16.0
tenacity==8.1.0
Werkzeug==2.2.2
zipp==3.8.1

Have you reloaded the web app after adding the virtualenv to the setup?

I am not 100% sure if I understand your correctly but I have reloaded my web app many times..

When I run in your bash console:

(myvirtualenv) 09:51 ~/lesko (main)$ python san.py Dash is running on http://127.0.0.1:8050/

  • Serving Flask app 'san'
  • Debug mode: on

It works ..

Not sure where to go with it now, can you advice something else maybe?

/UPDATE - it doesn't..

10:45 ~/lesko (main)$ python san.py Traceback (most recent call last): File "/home/piotrmichna/lesko/san.py", line 7, in <module> import dash_bootstrap_components as dbc ModuleNotFoundError: No module named 'dash_bootstrap_components'

I am also able to import it in the bash console:

(myvirtualenv) 11:00 ~/lesko (main)$ python
Python 3.9.13 (main, Jul 22 2022, 17:05:13) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> import dash
>>> import dash_bootstrap_components as dbc
>>> print('hmm')
hmm
>>>

Are you sure you're reading the most recent error traceback? It will be at the bottom of the error log.

My error log ash stop to update this morning. Nothing past 6:36. Might try again from scratch..

So let's start again.. Error message from log

2022-09-26 16:39:36,291: IndexError: list index out of range
2022-09-26 16:39:36,291:   File "/var/www/piotrmichna_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-09-26 16:39:36,291:     from poziomy import app
2022-09-26 16:39:36,291: 
2022-09-26 16:39:36,292:   File "/home/piotrmichna/meteo/poziomy.py", line 27, in <module>
2022-09-26 16:39:36,292:     latest_file = files_lst[-1]

When I print 'files_lst' they are there both from a dashboard and during running program:

files list ['/home/piotrmichna/meteo/levels/24.09.2022.csv', '/home/piotrmichna/meteo/levels/23.09.2022.csv', '/home/piotrmichna/meteo/levels/25.09.2022.csv']

When I run my app on pythonanywhere I got error:

    Traceback (most recent call last):
  File "/home/piotrmichna/meteo/poziomy.py", line 7, in <module>
    import dash_bootstrap_components as dbc
ModuleNotFoundError: No module named 'dash_bootstrap_components'

Any chance you could give me a hint please?

You're probably trying to list those files using relative paths without paying attention to the working directory: https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

Sorry I don't get you. Having flies in the list I cannot access them? Unfortunately due to nature of my graph I am having file updated every hour and a new file every day which I can't specify 'hard' in the path. Or am I missing something?

['/home/piotrmichna/meteo/levels/24.09.2022.csv', '/home/piotrmichna/meteo/levels/23.09.2022.csv', '/home/piotrmichna/meteo/levels/25.09.2022.csv']

This is my list. Why it throws an index error if the elements are there?

Could you show fragment of log where you print the list and get IndexError just after that?

I have the files sorted as it was a lack of knowledge error.. However I am facing this now:

2022-09-27 09:24:25 *** Starting uWSGI 2.0.20 (64bit) on [Tue Sep 27 09:24:22 2022] ***
2022-09-27 09:24:25 compiled with version: 9.4.0 on 22 July 2022 18:35:26
2022-09-27 09:24:25 os: Linux-5.15.0-1017-aws #21~20.04.1 SMP Tue Aug 16 15:49:47 UTC 2022
2022-09-27 09:24:25 nodename: blue-liveweb3
2022-09-27 09:24:25 machine: x86_64
2022-09-27 09:24:25 clock source: unix
2022-09-27 09:24:25 pcre jit disabled
2022-09-27 09:24:25 detected number of CPU cores: 4
2022-09-27 09:24:25 current working directory: /home/piotrmichna
2022-09-27 09:24:25 detected binary path: /usr/local/bin/uwsgi
2022-09-27 09:24:25 *** dumping internal routing table ***
2022-09-27 09:24:25 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2022-09-27 09:24:25 *** end of the internal routing table ***
2022-09-27 09:24:25 chdir() to /home/piotrmichna/
2022-09-27 09:24:25 your processes number limit is 256
2022-09-27 09:24:25 your memory page size is 4096 bytes
2022-09-27 09:24:25 detected max file descriptor number: 123456
2022-09-27 09:24:25 building mime-types dictionary from file /etc/mime.types...
2022-09-27 09:24:25 567 entry found
2022-09-27 09:24:25 lock engine: pthread robust mutexes
2022-09-27 09:24:25 thunder lock: disabled (you can enable it with --thunder-lock)
2022-09-27 09:24:25 uwsgi socket 0 bound to UNIX address /var/sockets/piotrmichna.pythonanywhere.com/socket fd 3
2022-09-27 09:24:25 Python version: 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0]
2022-09-27 09:24:25 PEP 405 virtualenv detected: /home/piotrmichna/.virtualenvs/myvirtualenv
2022-09-27 09:24:25 Set PythonHome to /home/piotrmichna/.virtualenvs/myvirtualenv
2022-09-27 09:24:25 *** Python threads support is disabled. You can enable it with --enable-threads ***
2022-09-27 09:24:25 Python main interpreter initialized at 0x5586c4edce70
2022-09-27 09:24:25 your server socket listen backlog is limited to 100 connections
2022-09-27 09:24:25 your mercy for graceful operations on workers is 60 seconds
2022-09-27 09:24:25 setting request body buffering size to 65536 bytes
2022-09-27 09:24:25 mapped 501384 bytes (489 KB) for 2 cores
2022-09-27 09:24:25 *** Operational MODE: preforking ***
2022-09-27 09:24:25 initialized 54 metrics
2022-09-27 09:24:25 Dash is running on http://127.0.0.1:8050/
2022-09-27 09:24:25  * Serving Flask app 'poziomy'
2022-09-27 09:24:25  * Debug mode: on
2022-09-27 09:24:25 unable to load configuration from /home/piotrmichna/uwsgi
2022-09-27 09:24:25 VACUUM: unix socket /var/sockets/piotrmichna.pythonanywhere.com/socket removed.

This line does not look promising to me:

2022-09-27 09:24:25 unable to load configuration from /home/piotrmichna/uwsgi

Can you see the problem there?

Problem solved!

Shout out to pythonanywhere team!