Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyMySQL version 0.10 produces ImportError crash on mycli execution #882

Closed
lukaus opened this issue Jul 18, 2020 · 19 comments · Fixed by #885
Closed

PyMySQL version 0.10 produces ImportError crash on mycli execution #882

lukaus opened this issue Jul 18, 2020 · 19 comments · Fixed by #885

Comments

@lukaus
Copy link

lukaus commented Jul 18, 2020

After updating PyMySQL from 0.9.3 to 0.10.0 the following crash occurs when executing mycli (version 1.12.1):

Traceback (most recent call last):
  File "/usr/bin/mycli", line 33, in <module>
    sys.exit(load_entry_point('mycli==1.21.1', 'console_scripts', 'mycli')())
  File "/usr/bin/mycli", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/<user>/.local/lib/python3.8/site-packages/mycli/main.py", line 41, in <module>
    from .sqlexecute import FIELD_TYPES, SQLExecute
  File "/home/<user>/.local/lib/python3.8/site-packages/mycli/sqlexecute.py", line 6, in <module>
    from pymysql.converters import (convert_mysql_timestamp, convert_datetime,
ImportError: cannot import name 'convert_mysql_timestamp' from 'pymysql.converters' (/home/<user>/.local/lib/python3.8/site-packages/pymysql/converters.py)

I downgraded to PyMySQL 0.9.3 to continue using mycli

@lukaus
Copy link
Author

lukaus commented Jul 18, 2020

Here's the commit that removed the convert_mysql_timestamp function:
PyMySQL/PyMySQL@fe0cd60#diff-40496cc4a0f4db6907de60f7ce470b95

@lunatiee
Copy link

solution 1) Install PyMySQL 0.9.2 (this is last version that you can use with mycli)

or

solution 2)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mycli/sqlexecute.py

Open the above file and modify it as follows:

line 6) from pymysql.converters import (convert_datetime,
line 102) FIELD_TYPE.TIMESTAMP: lambda obj: (convert_datetime(obj) or obj),

@fraoustin
Copy link
Contributor

If you want to use the last version of mycli, you can use mycli with docker https://hub.docker.com/repository/docker/dbcliorg/mycli

@artfulrobot
Copy link

I was new to doing this, so in case it helps anyone else, these are the commands I used to get it working based on @lunatiee 's solution ➊

$ pip3 install mycli
$ pip3 install -I PyMySQL==0.9.2

@amjith
Copy link
Member

amjith commented Jul 25, 2020

We have a sprint this weekend and we'll see if we can tackle this issue during the sprint.

If anyone is interested in participating, we're doing a virtual sprint through the PyOhio conference. https://www.pyohio.org/2020/events/sprints

@ZDSDESIRE
Copy link

ZDSDESIRE commented Jul 27, 2020

solution 1) Install PyMySQL 0.9.2 (this is last version that you can use with mycli)

or

solution 2)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mycli/sqlexecute.py

Open the above file and modify it as follows:

line 6) from pymysql.converters import (convert_datetime,
line 102) FIELD_TYPE.TIMESTAMP: lambda obj: (convert_datetime(obj) or obj),

This is an effective solution. Thank you!

@amjith
Copy link
Member

amjith commented Jul 27, 2020 via email

@artfulrobot
Copy link

yay, it works again. THANKS ALL!

@verajosemanuel
Copy link

not working even with the latest version in Cent Os

@ZDSDESIRE
Copy link

Not working even with the latest version in Win10:

Successfully installed mycli-1.22.1 prompt-toolkit-3.0.5

C:\Users\z_zon>mycli --help
Traceback (most recent call last):
  File "e:\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "E:\Python\Python38\Scripts\mycli.exe\__main__.py", line 4, in <module>
  File "e:\python\python38\lib\site-packages\mycli\main.py", line 9, in <module>
    from pwd import getpwuid
ModuleNotFoundError: No module named 'pwd'

I returned to mycli-1.21.1 and get it working based on @lunatiee 's solution ②: #882 (comment)

@amjith
Copy link
Member

amjith commented Jul 30, 2020

@verajosemanuel Can you tell me what is the version you're using? If you installed it via yum the latest version is probably not available via yum.

You need to install it via pip.

@amjith
Copy link
Member

amjith commented Jul 30, 2020

@ZDSDESIRE I can't reproduce it. Looks like the error you're seeing is very different from the original error reported.

Looks like there is an issue with your python installation. The module not found error is complaining about a module called pwd but this is a standard library module that is shipped with python. https://docs.python.org/3.8/library/pwd.html

You might want to reinstall python on your machine and try again.

@thorstenkampe
Copy link

@amjith pwd is Unix-only:

This module provides access to the Unix user account and password database. It is available on all Unix versions.

@thorstenkampe
Copy link

Looks like the developers are only testing on Linux or MacOS. On Windows mycli is completely broken because of the import of pwd.

@amjith
Copy link
Member

amjith commented Jul 31, 2020 via email

@amjith
Copy link
Member

amjith commented Aug 1, 2020

@thorstenkampe @ZDSDESIRE I'v created a branch that fixes the pwd import issue.

Can you try it out?

pip install -U https://github.com/dbcli/mycli/archive/pwd_optional.zip

@pasenor pasenor mentioned this issue Aug 1, 2020
2 tasks
@thorstenkampe
Copy link

@amjith seems to work fine

@verajosemanuel
Copy link

verajosemanuel commented Aug 3, 2020

ERROR: Package 'mycli' requires a different Python: 2.7.5 not in '>=3.6'

The above command should be:

pip3 install -U https://github.com/dbcli/mycli/archive/pwd_optional.zip

@ZDSDESIRE
Copy link

@amjith
Yay, it's working, thanks! Have you pulled out the pwd module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants