简体   繁体   English

如何在jupyter笔记本中的同一环境中在python包的本地副本和基本副本之间切换以进行开发

[英]How to switch between local copy and base copy of python package within same environment in a jupyter notebook for development

I realize that there are many similar questions to this, but the answers are all over my head.我意识到有很多与此类似的问题,但答案都在我的脑海中。 Most answers say to use virtualenv, and then just link to the virtualenv documentation, which assumes a high level of familiarity with managing packages and environments, so I'm having a hard time sorting out how to actually use it.大多数答案都说使用 virtualenv,然后只是链接到 virtualenv 文档,该文档假定对管理包和环境有很高的熟悉度,所以我很难弄清楚如何实际使用它。

I am making changes to an existing python package.我正在对现有的 python 包进行更改。 I cloned the GitHub repository to a local folder, created a branch, and am modifying the package within that branch (using Jupyter Lab).我将 GitHub 存储库克隆到本地文件夹,创建了一个分支,并修改了该分支中的包(使用 Jupyter Lab)。 All of this is happening inside a conda environment with the original package installed.所有这些都发生在安装了原始软件包的 conda 环境中。 I'm using Windows.我正在使用 Windows。 I would like to be able to test run functions from the package that incorporate the changes I've made, but currently, I think that the original, un-modified version of the package is being used (though I don't know how to confirm that, or how to check if the local version is being used).我希望能够测试包含我所做更改的包中的运行功能,但目前,我认为正在使用该包的原始未修改版本(尽管我不知道如何确认,或如何检查是否正在使用本地版本)。 I would also like to be able to switch back and forth between the original version and my version to compare the effects of the changes I'm making.我还希望能够在原始版本和我的版本之间来回切换,以比较我所做更改的效果。

I'm familiar with using conda and setting up environments and packages that way, and am also familiar with Jupyter.我熟悉使用 conda 并以这种方式设置环境和包,并且也熟悉 Jupyter。 I'm somewhat comfortable with GitHub (still getting used to it, find it often confusing and hard to understand).我对 GitHub 有点熟悉(仍然习惯它,发现它经常令人困惑且难以理解)。 I have no formal programming experience, so most documentation assumes a level of knowledge that I don't have.我没有正式的编程经验,因此大多数文档都假定我不具备一定的知识水平。 I'm confused by what virtualenv does differently than setting up an environment with conda.我对 virtualenv 与使用 conda 设置环境的不同之处感到困惑。 In conda, how would I specify to use a local version of a package rather than the installed one?在 conda 中,我如何指定使用本地版本的软件包而不是已安装的软件包? I'm also frustrated by many answers that don't specify where the suggested commands should be run from - within a notebook?我也对许多没有指定建议的命令应该从哪里运行的答案感到沮丧 - 在笔记本中? in anaconda prompt?在 anaconda 提示符下? in windows command prompt?在 Windows 命令提示符下? if so, what directory do I need to be in?如果是这样,我需要在哪个目录中?

Any answers that expand on what is already out there would be much appreciated by this beginner!这位初学者将非常感谢任何扩展现有内容的答案!

So after a LOT of searching and reading, this is what worked:所以经过大量的搜索和阅读,这是有效的:

How to import a module given the full path? 如何在给定完整路径的情况下导入模块?

import sys
sys.path.append('path/to/local/package/folder')  #this folder needs to have a file in it called yourpackagename.py (and an _init_.py file?)
import yourpackagename as pk

The way I checked that I had the version I wanted was to insert a function yourpackagename.version() in the version that I want to be modifying, so that when I call that function, it prints the statement "Yes, you are using the modified version."我检查我是否拥有我想要的版本的方法是在我想要修改的版本中插入一个函数yourpackagename.version() ,这样当我调用该函数时,它会打印语句“是的,你正在使用修改版。”

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

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