pythonrailway

How can I resolve this module error when deploying my Flask project in Railway?


I'm trying to fix this error that I receive when my Flask project gets built in Railway.

#11 8.037   Downloading MySQL-python-1.2.5.zip (108 kB)
#11 8.071      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 108.9/108.9 KB 3.3 MB/s eta 0:00:00
 
#11 8.085   Preparing metadata (setup.py): started
 
#11 8.261   Preparing metadata (setup.py): finished with status 'error'
#11 8.270   error: subprocess-exited-with-error
#11 8.270
#11 8.270   × python setup.py egg_info did not run successfully.
#11 8.270   │ exit code: 1
#11 8.270   ╰─> [8 lines of output]
#11 8.270       Traceback (most recent call last):
#11 8.270         File "<string>", line 2, in <module>
#11 8.270         File "<pip-setuptools-caller>", line 34, in <module>
#11 8.270         File "/tmp/pip-install-sxn61bzp/mysql-python_c2900c0eabc547e1a98d6870aca796df/setup.py", line 13, in <module>
#11 8.270           from setup_posix import get_config
#11 8.270         File "/tmp/pip-install-sxn61bzp/mysql-python_c2900c0eabc547e1a98d6870aca796df/setup_posix.py", line 2, in <module>
#11 8.270           from ConfigParser import SafeConfigParser
#11 8.270       ModuleNotFoundError: No module named 'ConfigParser'
#11 8.270       [end of output]
#11 8.270
#11 8.270   note: This error originates from a subprocess, and is likely not a problem with pip.
#11 8.273 error: metadata-generation-failed
#11 8.273
#11 8.273 × Encountered error while generating package metadata.
#11 8.273 ╰─> See above for output.
#11 8.273
#11 8.273 note: This is an issue with the package mentioned above, not pip.
#11 8.273 hint: See above for details.

I included MySQL-python in my requirements.txt file along with all of my other module installations. I tried specifying the version MySQL-python==1.2.5 and unsurprisingly that didn't do anything different...

Any help would be appreciated as I need to get this up and running soon.. Thank you!

**UPDATE after including configparser in requirements.txt **

I tried placing configparser==5.3.0 in my requirements.txt file and now the Railway Build Logs returns this error...

#11 6.821 Collecting MySQL-python
 
#11 6.826   Using cached MySQL-python-1.2.5.zip (108 kB)
#11 6.839   Preparing metadata (setup.py): started
 
#11 6.997   Preparing metadata (setup.py): finished with status 'error'
#11 7.004   error: subprocess-exited-with-error
#11 7.004
#11 7.004   × python setup.py egg_info did not run successfully.
#11 7.004   │ exit code: 1
#11 7.004   ╰─> [8 lines of output]
#11 7.004       Traceback (most recent call last):
#11 7.004         File "<string>", line 2, in <module>
#11 7.004         File "<pip-setuptools-caller>", line 34, in <module>
#11 7.004         File "/tmp/pip-install-vr58ik7u/mysql-python_bc531f9d2bda4605b1f01b756a7e81cb/setup.py", line 13, in <module>
#11 7.004           from setup_posix import get_config
#11 7.004         File "/tmp/pip-install-vr58ik7u/mysql-python_bc531f9d2bda4605b1f01b756a7e81cb/setup_posix.py", line 2, in <module>
#11 7.004           from ConfigParser import SafeConfigParser
#11 7.004       ModuleNotFoundError: No module named 'ConfigParser'
#11 7.004       [end of output]
#11 7.004
#11 7.004   note: This error originates from a subprocess, and is likely not a problem with pip.
#11 7.007 error: metadata-generation-failed
#11 7.007
#11 7.007 × Encountered error while generating package metadata.
#11 7.007 ╰─> See above for output.

UPDATE after installing mysql-connector-python

The project deploys, but when I tested one of my API's, I'm faced with this error which led me to try using the MySQL module...

[2023-02-04 10:15:46 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-02-04 10:15:46 +0000] [1] [INFO] Listening at: http://0.0.0.0:5456 (1)
[2023-02-04 10:15:46 +0000] [1] [INFO] Using worker: sync
[2023-02-04 10:15:46 +0000] [10] [INFO] Booting worker with pid: 10
[2023-02-04 10:16:36,128] ERROR in app: Exception on /api/login [POST]
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/util/_collections.py", line 1008, in __call__
return self.registry[key]
KeyError: <greenlet.greenlet object at 0x7f3bf8ab5040 (otid=0x7f3bfa061100) current active started main>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/venv/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/app/controllers/login.py", line 11, in login
user_exist = Users.query.filter_by(uname=user).first()
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 552, in __get__
return type.query_class(mapper, session=self.sa.session())
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/orm/scoping.py", line 47, in __call__
sess = self.registry()
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/util/_collections.py", line 1010, in __call__
return self.registry.setdefault(key, self.createfunc())
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 4228, in __call__
return self.class_(**local_kw)
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 176, in __init__
bind = options.pop('bind', None) or db.engine
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 998, in engine
return self.get_engine()
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1017, in get_engine
return connector.get_engine()
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 594, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/opt/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1027, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "<string>", line 2, in create_engine
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 548, in create_engine
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/opt/venv/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 163, in dbapi
return __import__("MySQLdb")
ModuleNotFoundError: No module named 'MySQLdb'

Solution

  • try, install pymysql, comment python-MysqlDb from requirements.txt and in main code file add

    import pymysql
    pymysql.install_as_MySQLdb()