Python 没有名为“pymysql”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33446347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:22:22  来源:igfitidea点击:

No module named 'pymysql'

pythonpython-3.xubuntupymysql

提问by troyz

I'm trying to use PyMySQL on Ubuntu.

我正在尝试在 Ubuntu 上使用 PyMySQL。

I've installed pymysqlusing both pipand pip3but every time I use import pymysql, it returns ImportError: No module named 'pymysql'

我已经pymysql使用两者安装pippip3但每次使用时import pymysql,它都会返回ImportError: No module named 'pymysql'

I'm using Ubuntu 15.10 64-bit and Python 3.5.

我使用的是 Ubuntu 15.10 64 位和 Python 3.5。

The same .py works on Windows with Python 3.5, but not on Ubuntu.

相同的 .py 可以在使用 Python 3.5 的 Windows 上运行,但不能在 Ubuntu 上运行。

采纳答案by user530873

Sort of already answered this in the comments, but just so this question has an answer, the problem was resolved through running:

已经在评论中回答了这个问题,但是这个问题有一个答案,问题是通过运行解决的:

sudo apt-get install python3-pymysql

回答by Yash Gupta

If even sudo apt-get install python3-pymysqldoes not work for you try this:

如果甚至sudo apt-get install python3-pymysql不适合你试试这个:

  • Go to the PyMySQL pageand download the zip file.
  • Then, via the terminal, cd to your Downloads folder and extract the folder
  • cd into the newly extracted folder
  • Install the setup.py file with: sudo python3 setup.py install
  • 转到PyMySQL 页面并下载 zip 文件。
  • 然后,通过终端,cd 到您的下载文件夹并解压缩该文件夹
  • cd 进入新解压的文件夹
  • 安装 setup.py 文件: sudo python3 setup.py install

回答by 3kstc

After trying a few things, and coming across PyMySQL Github, this worked:

在尝试了一些事情并遇到了PyMySQL Github 之后,这奏效了:

sudo pip install PyMySQL

sudo pip install PyMySQL

And to import use:

并导入使用:

import pymysql

import pymysql

回答by tim-oh

  1. Make sure that you're working with the version of Python that think you are. Within Python run import sysand print(sys.version).

  2. Select the correct package manager to install pymysql with:

    • For Python 2.x sudo pip install pymysql.
    • For Python 3.x sudo pip3 install pymysql.
    • For either running on Anaconda: sudo conda install pymysql.
    • If that didn't work try APT: sudo apt-get install pymysql.
  3. If all else fails, install the package directly:

    • Go to the PyMySQL pageand download the zip file.
    • Then, via the terminal, cd to your Downloads folder and extract the folder.
    • cd into the newly extracted folder.
    • Install the setup.py file with: sudo python3 setup.py install.
  1. 确保您使用的是您认为的 Python 版本。在 Python 中运行import sysprint(sys.version).

  2. 选择正确的包管理器来安装 pymysql:

    • 对于 Python 2.x sudo pip install pymysql
    • 对于 Python 3.x sudo pip3 install pymysql
    • 有关蟒蛇处于运行:sudo conda install pymysql
    • 如果这不起作用,请尝试 APT: sudo apt-get install pymysql
  3. 如果所有其他方法都失败,请直接安装软件包:

    • 转到PyMySQL 页面并下载 zip 文件。
    • 然后,通过终端,cd 到您的下载文件夹并解压缩该文件夹。
    • cd 进入新解压的文件夹。
    • 与安装setup.py文件:sudo python3 setup.py install

This answer is a compilation of suggestions. Apart from the other ones proposed here, thanks to the comment by @cmaher on this related thread.

这个答案是建议的汇编。除了这里提出的其他建议外,感谢@cmaher 在此相关线程上的评论。

回答by Mandeep Singh

sudo apt-get install python3-pymysql

sudo apt-get install python3-pymysql

This command also works for me to install the package required for Flask app to tun on ubuntu 16x with WISG module on APACHE2 server.

此命令也适用于我安装 Flask 应用程序所需的软件包,以在 APACHE2 服务器上使用 WISG 模块在 ubuntu 16x 上进行调整。

BY default on WSGI uses python 3 installation of UBUNTU.

默认情况下,WSGI 使用 UBUNTU 的 python 3 安装。

Anaconda custom installation won't work.

Anaconda 自定义安装不起作用。

回答by BigBadMe

I had this same problem just now, and found the reason was my editor (Visual Studio Code) was running against the wrong instance of python; I had it set to run again python bundled with tensorflow, I changed it to my Anaconda python and it worked.

我刚才也遇到了同样的问题,发现原因是我的编辑器(Visual Studio Code)运行的是错误的 python 实例;我将它设置为再次运行与 tensorflow 捆绑在一起的 python,我将其更改为我的 Anaconda python 并且它起作用了。

回答by Etoneja

Use:

用:

import pymysql

Not:

不是:

import PyMySQL

That works for me.

这对我行得通。

回答by AlmostPitt

I ran into the same problem earlier, but solved it in a way slightly different from what we have here. So, I thought I'd add my way as well. Hopefully, it will help someone!

我之前遇到过同样的问题,但解决的方法与我们这里的方法略有不同。所以,我想我也会添加我的方式。希望它会帮助某人!

sudo apt-get install mysql-clientdidn't work for me. However, I have Homebrew already installed. So, instead, I tried:

sudo apt-get install mysql-client对我不起作用。但是,我已经安装了 Homebrew。所以,相反,我尝试:

brew install mysql-client

Now, I don't get the error any more.

现在,我不再收到错误消息。

Good luck!

祝你好运!

回答by Yuqin Peng

Just a note: for Anaconda install packages command:

请注意:对于 Anaconda 安装包命令:

  1. python setup.py install
  1. python setup.py 安装

回答by jason m

fwiw, for a conda env:

fwiw,对于 conda env

 conda install -c anaconda pymysql