I am working with a LAMP install from GCP on a debian 9 machine. Default GCP Lamp settings https://cloud.google.com/solutions/web-hosting
I am having some dependency error trying to import pymysql into a project. I don't fully understand the error, or exactly what I am missing. This is the error I am getting:
>>> import pymysql
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/philip_plachta/.local/lib/python3.5/site-packages/pymysql/__init__.py", line 59, in <module>
from . import connections # noqa: E402
File "/home/philip_plachta/.local/lib/python3.5/site-packages/pymysql/connections.py", line 206
):
Here are the python packages I currently have installed
~$ python3 -m pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=
(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
certifi (2020.12.5)
chardet (4.0.0)
connect.py (0.4.2)
cryptography (1.7.1)
idna (2.10)
keyring (10.1)
keyrings.alt (1.3)
mysql-connector-python (8.0.23)
pip (9.0.1)
protobuf (3.15.3)
pyasn1 (0.1.9)
pycrypto (2.6.1)
pycurl (7.43.0)
pygobject (3.22.0)
PyMySQL (1.0.0)
python-apt (1.4.3)
pyxdg (0.25)
requests (2.25.1)
SecretStorage (2.3.1)
setuptools (33.1.1)
six (1.10.0)
unattended-upgrades (0.1)
urllib3 (1.26.3)
wheel (0.29.0)
Below is roughly what I have tried. Its gotten a little bit messy because I've tried many things and uninstalled things and reinstalled them and so on. I am not opposed to starting again from scratch, but if I can get a little direction from someone with more experience than me it would be greatly appreciated!
sudo apt-get install python3-pip
sudo apt-get install python3-pymysql
sudo python3 -m pip install Pymysql
sudo python3 -m pip install mysql-connector-python
Edit / Solution
snakecharmerb offered the advice of using sudo apt install python3-pymysql. This fixed it for me on a new instance of the GCP Lamp Server. I couldn't get (gave up) to work on the other one. I'm assuming something I installed or uninstalled messed something up as snakecharmerb is suggesting, but it's not worth the time for me to try to find it when I can make a new server and just do apt install python3-mysql from the start.
Thank you.
Edit Edit Here is the process I followed on the new server that seemed to set things up correctly for me
FROM THE START:
(First Goal is to access mysql from my local machine)
sudo apt update
sudo apt install php7.4-mbstring -y
(Create a mysql user)
sudo mysql -u root -p
CREATE USER 'username'@'%.%.%.%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *. * TO 'username'@'%.%.%.%';
(Open to the outside world)
https://phoenixnap.com/kb/mysql-remote-connection
Also had to create an ingress rule to allow sql to be accessed (via firewall in gcp) on 0.0.0.0/0 on port 3306
(Then...)
sudo apt update
sudo apt list --upgradable
sudo apt upgrade
(Second goal is to allow my scripts to run on the machine)
sudo apt install python3-pip -y
sudo apt install python3-pymysql -y
sudo apt install python3-mysql.connector -y
On my Debian 9 machine, sudo apt-get install pymysql installs PyMySQL (0.7.10) (according to pip3 list), which imports without error in the interpreter. It looks like you have installed a later version locally, which contains syntax that isn't compatible with Python 3.5. I'd suggest uninstalling the version in ~/.local and trying to use the version installed by apt
snakecharmerb offered the advice of using sudo apt install python3-pymysql. This fixed it for me on a new instance of the GCP Lamp Server. I couldn't get (gave up) to work on the other one. I'm assuming it was something stupid on my part - something I installed or uninstalled messed something up as snakecharmerb is suggesting, but it's not worth the time for me to try to find it when I can make a new server and just do 'apt install python3-mysql' from the start.
Thank you.
Edit /The Process I followed to get things to work on a new server
FROM THE START:
(First Goal is to access mysql from my local machine)
sudo apt update
sudo apt install php7.4-mbstring -y
(Create a mysql user)
sudo mysql -u root -p
CREATE USER 'username'@'%.%.%.%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *. * TO 'username'@'%.%.%.%';
(Open to the outside world)
https://phoenixnap.com/kb/mysql-remote-connection
Also had to create an ingress rule to allow sql to be accessed (via firewall in gcp) on 0.0.0.0/0 on port 3306
(Then...)
sudo apt update
sudo apt list --upgradable
sudo apt upgrade
(Second goal is to allow my scripts to run on the machine)
sudo apt install python3-pip -y
sudo apt install python3-pymysql -y
sudo apt install python3-mysql.connector -y