在Anaconda中安装PyMySQL
我安装了两个版本的Python。
一个是Python 2.7.2(默认,2011年6月12日,15:08:59)[MSC v.1500 32位(Intel)],运行在win32上。
另一个是Python 2.7.7 | Anaconda 2.0.1(64位)|(默认,2014年6月11日,10:40:02)[MSC v.1500 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数据服务器呢?
3 个回答
0
我也遇到过同样的问题。这个问题是通过运行命令 conda install pymysql 来解决的。
1
我可以在我的Ubuntu系统上通过命令 conda install pymysql
来安装pymysql。如果遇到文件权限的问题,可以运行命令 sudo chmod -R 777 youAnacondaPath/anaconda3
来解决。
1
我花了一段时间才明白,原来这个问题是通过用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 ...