我有一个项目文件夹,里面有很多不同的子文件夹。我想在许多不同的笔记本和脚本中使用一些功能。出于这个原因,我决定将它们打包并安装在我的环境中,以便我可以在环境中可靠地访问它们。现在的问题是看起来包已经安装好了。但是,我无法将其导入脚本或笔记本中。
这是我尝试在启用的环境中安装 utils 包:
conda install conda-build -y
cd /home/path/to/project/tools/utils
conda develop .
pip install -e .
命令
which pip
、which python
和which conda
通向路径
/home/user/miniconda3/envs/env_name/bin/
命令
conda list | grep utils
将显示:
utils 1.0.0 dev_0 <develop>
我的
./tools/utils/setup.py
长相如下:
from setuptools import setup
setup(
name="utils",
version="1.0.0",
author="My Name",
description="A collection of useful functions for the Project",
install_requires=[
"requests>=2.25.1",
"numpy>=1.20.2",
"pandas>=1.2.4",
"matplotlib>=3.4.2",
"opencv-python>=4.5.2.54",
"tqdm>=4.60.0"
]
)
我以为是conda安装有问题,所以我把整个项目搬到了Windows机器上,在那里也设置了环境,并安装了utils包。在两台机器上,当我运行
python
>>> import utils
在环境中,反应是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'utils'
因为它在我的两个设备上都是一样的,我猜一定是我的环境设置有问题,或者本地可编辑库的安装过程有问题。为此,我还没有费心去重装conda
我希望有人能给我一些关于如何解决这个问题的提示......提前谢谢你。
更新:我在 Linux 机器上重新安装了 miniconda,将
setup.py
文件中的包重命名为“myutils”并删除了请求依赖并制作了一个 wheel 文件
python setup.py bdist_wheel
这样我就可以使用打包的版本,安装它使用
pip install ./dist/myutils-1.0-py3-none-any.whl
我还有同样的问题...