简体   繁体   English

Pycharm - 编辑已安装的包

[英]Pycharm - edit installed package

I have Pycharm 2017.2 connected to vagrant 1.9.7 I want to change some line in installed package.我将 Pycharm 2017.2 连接到 vagrant 1.9.7 我想更改已安装包中的某些行。

It is possible only by editing /lib/python/site-packages/ inside vagrant using vim or other cli editor.只有使用 vim 或其他 cli 编辑器在 vagrant 中编辑 /lib/python/site-packages/ 才有可能。 When i try to edit anything in Pycharm it asks for permission to edit non project file firstly, but changes don't cause server reload in debug mode.当我尝试在 Pycharm 中编辑任何内容时,它首先要求编辑非项目文件的权限,但更改不会导致服务器在调试模式下重新加载。 Additionally, inserted code is not executed.此外,不会执行插入的代码。 Is it possible to edit installed packages in Pycharm?是否可以在 Pycharm 中编辑已安装的软件包?

EDIT: One answer shows how to do it by installing packages with -e option.编辑:一个答案显示了如何通过安装带有 -e 选项的软件包来做到这一点。

Is there any way to edit this packages when they are installed normally without -e option?在没有 -e 选项的情况下正常安装时,有没有办法编辑这些包?

With this solution you can edit & debug 3rd party packages in PyCharm.使用此解决方案,您可以在 PyCharm 中编辑和调试 3rd 方包。

Prerequisites:先决条件:

  1. Fork & clone the repo you want to edit on your host.分叉并克隆您要在主机上编辑的存储库。 Say to /on-your-host/path/to/3rd-party对 /on-your-host/path/to/3rd-party 说
  2. In your Vagrantfile , configure your synced_folder from /on-your-host/path/to/3rd-party to /vagrant/3rd-party在您的Vagrantfile 中,将您的synced_folder从 /on-your-host/path/to/3rd-party 配置为 /vagrant/3rd-party

In Terminal:在终端:

  1. ssh into your vagrant ssh 进入你的流浪汉
  2. Activate the project's virtualenv, if any激活项目的 virtualenv,如果有的话
  3. pip install -e /vagrant/3rd-party pip install -e /vagrant/3rd-party

In PyCharm:在 PyCharm 中:

  1. Set your Project Interpreter > Gear icon > Add Remote > Vagrant设置您的项目解释器 > 齿轮图标 > 添加远程 > Vagrant
  2. Create a run/debug configuration for your needs根据您的需要创建运行/调试配置
  3. Run/debug it运行/调试它
  4. Add breakpoints inside the 3rd party package在 3rd 方包内添加断点
  5. You should be able to edit and use the debugger on this code now您现在应该能够在此代码上编辑和使用调试器

Notes:笔记:

  1. Pip install in edit mode docs 在编辑模式下安装 Pip 文档
  2. Forking is optional.分叉是可选的。 If you just want to play around, without contributing, then skip forking and just clone the original repo on your host.如果你只是想玩玩,而不做贡献,那么跳过分叉并在你的主机上克隆原始存储库。
  3. You may need to refresh PyCharm external libraries .您可能需要刷新 PyCharm 外部库
    1. In my case was enough to right click on the 3rd party package name (from the breadcrumbs) and delete it在我的情况下,右键单击第 3 方包名称(从面包屑中)并删除它就足够了
    2. Then Settings > Project Interpreter: click gear icon > More > click edit icon > OK, OK, OK然后设置>项目解释器:单击齿轮图标>更多>单击编辑图标>确定,确定,确定

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM