如何将文件夹添加到给定 Anaconda 环境的搜索路径?

2022-01-10 00:00:00 python python-3.x anaconda

问题描述

我正在用 Python 开发一个项目,我想包含一些自己的模块,这些模块不在常规 Python 搜索路径中,我想添加它们.但是,我只想为我在开发期间使用的 Anaconda 环境执行此操作,并且我希望它们随着时间的推移保持在那里(即,当我重新启动环境时,我希望搜索路径具有该文件夹).

I am developing a project in Python and I want to include some own modules which are not on the regular Python search path and I want to add them. However, I want to do this just for the Anaconda environment I am using during development and I would like them to remain there over time(i.e. when I restart the environment, I want the search path to have that folder).

谢谢!


解决方案

可以用

conda develop <directory>

这会将 conda.pth 文件写入环境的 site-packages 目录,这将导致您的目录添加到 sys.path.

This will write a conda.pth file to the environment's site-packages directory which will cause your directory to be added to the sys.path.

相关文章