在Python虚拟环境中使用环境外的mysql

环境:win8 64bit、Python2.7、mysql 5.6.20,

Python和mysql连接使用MySQL-python-1.2.3.win32-py2.7

描述:

我是下载MySQL-python-1.2.3.win32-py2.7.exe后双击打开运行安装,安装正确,可以在cmd命令行正确启动数据库。但是我需要在virtualenv环境下使用mysql,问题出现了:

由于安装MySQL-python-1.2.3.win32-py2.7是下载后双击打开安装的,也就是说在虚拟环境外部安装的,所以在venv环境中import MySQLdb时提示没又该模块。但是又要在虚拟环境中使用,请各位老师指点一番,谢谢

1:在虚拟环境中如何安装MySQL-python-1.2.3.win32-py2.7

2:在虚拟环境中是否能够引入环境外的包

6个回答

终于找到方法了,马上哭出来了。。。。。
pip install --allow-external mysql-connector-python mysql-connector-python
要写两遍,难道是重要的工具要写两遍。。。。
测试成功

图片说明


图片说明

网上搜的下述方法也是不对

 > pip install mysql-connector-python
You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Collecting mysql-connector-python
  Could not find a version that satisfies the requirement mysql-connector-python (from ve
rsions: )
  Some externally hosted files were ignored as access to them may be unreliable (use --al
low-external mysql-connector-python to allow).
No matching distribution found for mysql-connector-python

(venv) Think@RESEARCH E:\test
> pip install --allow-external mysql-connector-python \mysql-connector-python
You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Exception:
Traceback (most recent call last):
  File "E:\test\venv\lib\site-packages\pip\basecommand.py", line 223, in main
    status = self.run(options, args)
  File "E:\test\venv\lib\site-packages\pip\commands\install.py", line 268, in run
    wheel_cache
  File "E:\test\venv\lib\site-packages\pip\basecommand.py", line 268, in populate_requirement_set
    wheel_cache=wheel_cache
  File "E:\test\venv\lib\site-packages\pip\req\req_install.py", line 207, in from_line
    wheel_cache=wheel_cache)
  File "E:\test\venv\lib\site-packages\pip\req\req_install.py", line 66, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "E:\test\venv\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2960, in parse

    reqs = list(parse_requirements(s))
  File "E:\test\venv\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2891, in parse_requirements
    raise ValueError("Missing distribution spec", line)
ValueError: ('Missing distribution spec', '\\mysql-connector-python')

虚拟环境中选择源码来python setup.py install安装。

deyuzhi
is_thinking 请问如何用这种方法安装呢?谢谢
接近 5 年之前 回复

图片说明

如果你可以安装mysql-python globally (in C:/python27) ( http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python)。你把你的python目录lib/site-package

  • MySQL_python-1.2.4-py2.7.egg-info(folder)
  • MySQLdb(folder)
  • _mysql_exceptions.py/.pyc/.pyo
  • _mysql.pyd、

这四个文件复制到你的虚拟环境的site-packages目录下,就可以使用了

guo070110053
guo070110053 搞了一下午终于好了,感谢楼主
3 年多之前 回复

搞了一下午终于好了,感谢楼主

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问