创建项目后,创建一个继承全局站点包的 PyCharm 项目? [英] Make a PyCharm project inheriting global site-packages, after creating the project?

查看:433
本文介绍了创建项目后,创建一个继承全局站点包的 PyCharm 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PyCharm 和 Mac OS 的新手.我用 VirtualEnv 在 PyCharm 中创建了一个 python 项目,我没有选择继承全局站点包"选项.在这个项目上工作了一段时间后,我意识到我需要继承一些全局安装的包.

这里有一个解决方法,它创建一个共享的虚拟环境并使用它:

  • 然后选择Show all...",选择你想要改变的虚拟环境,点击这个图标,将全局包的路径添加到这个venv的路径中

  • 然后单击确定"或应用"以使其工作.通常,全局包的路径是/path-to-python/Lib/site-packages",我的桌面是:

    现在您可以在 venv 中使用所有全局包.对于 Windows 以外的任何系统,这也应该可以正常工作.

    但是你不会在 pycharm 的包查看器中看到这个 venv 的任何全局包,这完全有道理,因为 pycharm 只能为你管理 venv,而不是全局包.

    <小时>

    对于您的单独问题:是的.因为您只将全局路径添加到您的 venv 中,而不是将所有包文件复制到其中.添加全局路径后,所有全局包都应该可以在您的 venv 中随时运行.

    I'm a newbie with PyCharm and Mac OS. I created a python project in PyCharm with VirtualEnv, and I didn't select the option of 'Inherit global site packages'. After working on this project for a while, I realized I need to inherit some packages that are installed globally.

    There is a workaround here, which creates a shared Virtual Environment and uses it: Create shared virtual env. However, I wonder whether there is any way to make changes to current project, rather than creating a new project or creating a shared virtual environment?


    A separate question: assuming that I have a project that inherits global packages. If after the project's creation, I installed other packages globally, will those packages available in this project?

    Thank you very much for your help. Any suggestion is appreciated.

    解决方案

    I figured this out when clicking around.

    1. In Pycharm, go to File -> Settings... -> Project -> Project Interpreter, click on the gear icon next to the menu:

    2. Then choose "Show all...", and select the virtual environment you want to change, click this icon to add global packages' path into this venv's path

    then click ok or apply to make it work. Usually, your global packages' path is "/path-to-python/Lib/site-packages", for my desktop is:

    Now you can use all your global packages within the venv. For any system other than Windows, this should work fine as well.

    But you won't see any global packages in pycharm's package viewer for this venv, which totally makes sense, because pycharm can only manager the venv for you, not the global one.


    For your separate question: Yes. Because you only add global path into your venv, not like copying all package files into it. After adding the global path, all global packages should work inside your venv at any time.

    这篇关于创建项目后,创建一个继承全局站点包的 PyCharm 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆