安装PyMySQL到Anaconda Python

3
我已经安装了两个版本的Python。
Python 2.7.2 (默认, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (默认, Jun 11 2014, 10:40:02) [MSC v.1500 64 bit (AMD64)] on 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目录下使用MySQL连接模块,但是它并没有起作用。我还能尝试什么?如果这不可行,那么我可以在Anaconda中使用哪个库来访问MySQL数据服务器?


关于为什么你尝试的第一步没有成功:看起来 PyMySQL 目前还不被 Anaconda 支持:http://docs.continuum.io/anaconda/pkg-docs.html 但这并不意味着你不能自己安装它,所以你尝试的第二步应该可以工作。 - mechanical_meat
似乎Anaconda正在安装该库,但当我调用它时,它找不到它。 - Daniel
尝试使用 import sys; sys.path 命令,确保安装目录已添加到路径中。 - mechanical_meat
让我们在聊天中继续这个讨论 - Daniel
我恐怕现在谈论这个主题并不能帮上忙,因为我目前没有任何想法。 - mechanical_meat
显示剩余3条评论
3个回答

1
我可以使用命令conda install pymysql在我的Ubuntu系统上安装pymysql,如果有任何文件权限问题,请运行命令sudo chmod -R 777 youAnacondaPath/anaconda3。请注意保留HTML标签。

1

在意识到问题可以通过使用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()

尝试直接从命令行运行脚本(导入失败):
(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 ...

0

我曾经遇到过同样的问题,但是通过conda install pymysql解决了这个问题。


这更适合作为评论而不是答案。或者你可以丰富它,使其更好 :) - Til
对我来说不起作用,很奇怪。Conda声称已经安装了它,但是导入仍然失败。 - Ben Farmer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接