【问题标题】:Installing PyMySQL for Anaconda python为 Anaconda python 安装 PyMySQL
【发布时间】:2014-11-07 02:54:29
【问题描述】:

我已经安装了两个版本的 python。

Win32 上的 Python 2.7.2(默认,2011 年 6 月 12 日,15:08:59)[MSC v.1500 32 位(英特尔)]

Python 2.7.7 |Anaconda 2.0.1(64 位)| (默认,2014 年 6 月 11 日,10:40:02)[MSC v.1 500 64 位 (AMD64)] 在 win32 上

我正在尝试为 anaconda python 包安装 PyMySQL,问题是当我尝试安装它时,它安装在 Python 2.7.2 中。我怎样才能成功安装 anaconda 版本的库。我尝试使用 anaconda 命令

conda install PyMySQ

但没用 也试过了

python.exe  C:\Users\jimenez\Downloads\PyMySQL-0.6.2\setup.py install

这就是发生的事情

C:\Anaconda>python.exe  C:\Users\jimenez\Downloads\PyMySQL-0.6.2\setup.py install
running install
running bdist_egg
running egg_info
writing PyMySQL.egg-info\PKG-INFO
writing top-level names to PyMySQL.egg-info\top_level.txt
writing dependency_links to PyMySQL.egg-info\dependency_links.txt
warning: manifest_maker: standard file 'setup.py' not found

reading manifest file 'PyMySQL.egg-info\SOURCES.txt'
writing manifest file 'PyMySQL.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
warning: install_lib: 'build\lib' does not exist -- no Python modules to install


creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\EGG-INFO
copying PyMySQL.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying PyMySQL.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying PyMySQL.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-I
NFO
copying PyMySQL.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\PyMySQL-0.6.2-py2.7.egg' and adding 'build\bdist.win-amd64\egg' t
o it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing PyMySQL-0.6.2-py2.7.egg
Removing c:\anaconda\lib\site-packages\PyMySQL-0.6.2-py2.7.egg
Copying PyMySQL-0.6.2-py2.7.egg to c:\anaconda\lib\site-packages
PyMySQL 0.6.2 is already the active version in easy-install.pth

Installed c:\anaconda\lib\site-packages\pymysql-0.6.2-py2.7.egg
Processing dependencies for PyMySQL==0.6.2
Finished processing dependencies for PyMySQL==0.6.2

C:\Anaconda>python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC v.1
500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import PyMySQL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyMySQL

在 anaconda 目录中,但它也不起作用。我还能尝试什么?在这种情况下,我可以在 anaconda 中使用什么库来访问 mysql 数据服务器是不可能的?

【问题讨论】:

  • 至于为什么您尝试的第一步不起作用:Anaconda 似乎还不支持 PyMySQL:docs.continuum.io/anaconda/pkg-docs.html 但这并不意味着您不能安装它你自己的,所以你尝试的第二步应该可以工作。
  • 似乎 anaconda 正在安装库,但是当我调用它时,它找不到它
  • 尝试:import sys; sys.path 确保安装它的目录在路径上
  • 我认为它在那里 >>> sys.path ['', 'C:\\Anaconda\\lib\\site-packages\\pymysql-0.6.2-py2.7.egg '
  • 啊,导入应该是小写的。请尝试:import pymysql

标签: python anaconda pymysql


【解决方案1】:

我也遇到过同样的问题。 conda install pymysql 解决了这个问题。

【讨论】:

  • 这更好地作为评论而不是答案。或者,也许您可​​以丰富它以使其更好:)
  • 奇怪的是,对我不起作用。 Conda 声称已安装它,但导入仍然失败。
【解决方案2】:

我为此苦苦挣扎了一段时间,然后才意识到通过使用 python 调用 python 脚本解决了这个问题(有点奇怪)。我在 Windows 上使用 Anaconda。

从 python 导入工作正常:

(root) c:\python_scripts>python
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> quit()

尝试直接从 cmd 运行脚本(导入失败):

(root) c:\python_scripts>script.py
Traceback (most recent call last):
  File "C:\python_scripts\GRAMR\CTA_monitor.py", line 5, in <module>
    import pymysql
ImportError: No module named pymysql

使用“python”运行:

(root) c:\python_scripts>python script.py
Script working ...

【讨论】:

    【解决方案3】:

    我可以在我的ubuntu系统上使用命令conda install pymysql安装pymysql,如果有任何文件权限问题,运行命令sudo chmod -R 777 youAnacondaPath/anaconda3

    【讨论】:

      猜你喜欢
      • 2020-08-29
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 2016-04-19
      • 2020-08-13
      • 2016-05-24
      相关资源
      最近更新 更多