在使用pip安装Python模块后,如何启动该模块的主要功能?

2024-10-01 17:24:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python 3project。我正在本地开发它

我试图通过cd将它安装到项目目录中,然后执行

pip3 install .

结果是:

Processing /Users/XXXXX/dev/misc/rec2sqlite
Building wheels for collected packages: rec2sqlite
  Building wheel for rec2sqlite (setup.py) ... done
  Created wheel for rec2sqlite: filename=rec2sqlite-1.0-py3-none-any.whl size=3758 sha256=77225f8b2444fb4143ffb2aa70ee22735eff591452ba777387cc10b42f21b6ac
  Stored in directory: /private/var/folders/pt/7nsl9k8d6q56bwj9nc6lydzh0000gn/T/pip-ephem-wheel-cache-_voecun1/wheels/8b/47/6c/df4c285c608c63e5b3d6df78ec193cf038b3d4a56f4e3b2420
Successfully built rec2sqlite
Installing collected packages: rec2sqlite
  Attempting uninstall: rec2sqlite
    Found existing installation: rec2sqlite 1.0
    Uninstalling rec2sqlite-1.0:
      Successfully uninstalled rec2sqlite-1.0
Successfully installed rec2sqlite-1.0

然后我转到另一个目录,想运行main函数。我输入了python3 rec2sqlite,得到了以下输出:

/usr/local/bin/python3: can't open file 'rec2sqlite': [Errno 2] No such file or directory

在使用pip安装当前版本后,为了能够运行main function,我需要在源代码和/或使用的命令中更改什么


Tags: pip目录formainpackagescdwheelsdirectory
2条回答

从项目目录中运行python3 rec2sqlite时会发生什么情况? 如果您必须从另一个目录运行它,您可以尝试使用目录python3 /<path-to-project-directory>/rec2sqlite的完整路径

This answer有帮助。要修复错误,我必须执行以下操作:

  1. 将主功能代码放入文件__main__.py
  2. 使用项目目录中的pip3 install .安装包
  3. 使用python3 -m <moduleName>(例如python3 -m rec2sqlite)运行步骤2中安装的程序

相关问题 更多 >

    热门问题