Anaconda保留缓存模块 [英] Anaconda keeps caching modules
问题描述
如何防止Anaconda缓存我的模块?每次我在代码库中的特定文件中进行更改(其包含的文件夹具有__init__.py
文件)时,python均无法识别这些更改,并继续执行该文件的先前版本,而该版本恰好被缓存在anaconda3/lib/python3.6/site-packages/"the name of the main module"
.
How can I prevent Anaconda from caching my module? Every time that I make a change in a specific file in my codebase (for which the containing folder has a __init__.py
file), python does not recognize those changes and keeps executing the previous version of the file, which happens to be cached at anaconda3/lib/python3.6/site-packages/"the name of the main module"
.
推荐答案
如果要开发软件包,最好对其中一个安装程序使用develop
选项.这将创建一个指向开发目录的链接,而不是复制文件,因此您可以测试更新的代码.例如,如果您有一个目录,例如:
If you are doing development of a package, it is best to use the develop
option to one of the installers. This creates a link to the development directory, rather than copying files, so you can test your updated code. For instance, if you have a directory like:
project
|── setup.py
|── package_name/
|── __init__.py
|── module.py
您可以通过使用setup.py
在目录中运行以下命令之一来以开发模式安装(请注意,命令末尾的点.
很重要):
You can install in development mode by running one of the following commands in the directory with setup.py
(and note that the dots .
at the ends of the commands are important):
-
conda develop .
(需要安装conda-build
)- 使用
conda develop --uninstall .
卸载
conda develop .
(requiresconda-build
to be installed)- Uninstall with
conda develop --uninstall .
- 使用
pip uninstall package_name
卸载
- 使用
python setup.py develop --uninstall
卸载
在您遇到的情况下,您应该执行的操作是根据安装的方式使用
conda
或pip
删除已安装的程序包,然后使用开发模式将更改合并到代码中.In your situation, what you should do is remove the installed package, either with
conda
orpip
, depending on how you installed it, and then use the develop mode to incorporate changes in your code.请注意,每次要使用更改后的代码时,都需要重新启动Python解释器(如果以交互方式运行).另一个选择是使用IPython和
autoreload
扩展 ,但请注意文档中有关使用该功能的注意事项.Note that you will need to restart the Python interpreter (if you're running in interactive mode) every time you want to use the changed code. Another option is to use IPython and the
autoreload
extension, although note the caveats about using that in the documentation.也相关: Python setup.py开发与安装
这篇关于Anaconda保留缓存模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Uninstall with
- 使用