Python 3虚拟环境使用PyMySQL

时间:2018-06-01 00:39:30

标签: python python-3.x flask virtualenv pymysql

服务器的默认Python版本是2.6。 Python 3也已安装,我创建了一个虚拟环境(python3 -m venv py3env)并在虚拟环境中安装了Flask和PyMySQL。

但是,在配置Web服务器(Apache + WSGI)之后,应用程序无法正常工作并抛出以下错误:

       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 699, in __init__
  self.connect()
       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 935, in connect
     self._get_server_information()
       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 1249, in _get_server_information
         packet = self._read_packet()
       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 991, in _read_packet
         packet_header = self._read_bytes(4)
       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 1025, in _read_bytes
         data = self._rfile.read(num_bytes)

       File "/usr/lib64/python2.6/io.py", line 940, in read
         return self._read_unlocked(n)
       File "/usr/lib64/python2.6/io.py", line 974, in _read_unlocked
         chunk = self.raw.read(wanted)
       File "/usr/lib64/python2.6/io.py", line 591, in read
         n = self.readinto(b)

       File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/_socketio.py", line 59, in readinto
         return self._sock.recv_into(b)
     TypeError: recv_into() argument 1 must be pinned buffer, not bytearray
  • 我尝试通过pip安装python-socketio,但它仍然没有被使用。
  • MySQL-python已安装在服务器上。

如何强制应用程序使用虚拟环境的版本?

0 个答案:

没有答案