美文网首页生活不易 我用pythonPython 运维
windows下搭建并使用python虚拟环境

windows下搭建并使用python虚拟环境

作者: EldonZhao | 来源:发表于2017-04-14 16:44 被阅读377次

    虚拟环境搭建:

    一、安装python:

    参考Eclipse+python开发环境搭建,这里不再赘述。

    二、安装pip: 参考python包安装工具pip使用总结【windows】,这里不再赘述。

    三、安装virtualenv和virtualenvwrapper:

    > python -m pip install virtualenvwrapper-win
    

    四、创建python虚拟环境:

    D:\MyDrivers>virtualenv django1_7
    New python executable in D:\MyDrivers\django1_7\Scripts\python.exe
    Installing setuptools, pip, wheel...done.
    

    五、激活虚拟环境:

    D:\MyDrivers\django1_7>Scripts\activate.bat
    (django1_7) D:\MyDrivers\django1_7>
    

    六、去激活虚拟环境:

    (django1_7) D:\MyDrivers\django1_7>Scripts\deactivate.bat
    

    虚拟环境使用:

    以运行基于django1.7.4框架的项目为例:

    • 安装django1.7.4:
    django1_7) D:\EldonZhao\git\vpc>pip install django===1.7.4
    
    • 启动项目并解决相关错误:
    (django1_7) D:\EldonZhao\git\vpc>python manage.py runserver
    ImportError: Could not import settings 'project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named djcelery
    (django1_7) D:\EldonZhao\git\vpc>pip install django-celery
    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
    # 从http://pan.baidu.com/s/1kUXl1P1下载文件包,并解压到到虚拟环境Lib\site-packages下面。
    
    ImportError: No module named IPy
    (django1_7) D:\EldonZhao\git\vpc>pip install IPy
    ImportError: No module named iptools.ipv4
    (django1_7) D:\EldonZhao\git\vpc>pip install iptools
    ImportError: No module named pymongo
    (django1_7) D:\EldonZhao\git\vpc>pip install pymongo
    ImportError: No module named redisco.containers
    (django1_7) D:\EldonZhao\git\vpc>pip install redisco
    ImportError: No module named redis
    (django1_7) D:\EldonZhao\git\vpc>pip install redis
    
    • 启动成功:
    System check identified no issues (0 silenced).
    April 14, 2017 - 16:43:34
    Django version 1.7.4, using settings 'project.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CTRL-BREAK.
    

    参考资料:

    相关文章

      网友评论

        本文标题:windows下搭建并使用python虚拟环境

        本文链接:https://www.haomeiwen.com/subject/madbwttx.html