简体   繁体   English

使用 pip 安装后,如何启动这个 Python 模块的主要 function?

[英]How can I start the main function of this Python module after installing it using pip?

I have a Python 3 project .我有一个 Python 3项目 I am developing it locally.我正在本地开发它。

I tried to install it by cd ing into the project directory and then executing我尝试通过cd进入项目目录然后执行来安装它

pip3 install .

The resulting output was:结果 output 是:

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

Then I went to another directory and wanted to run the main function. I entered python3 rec2sqlite and got the following output:然后进入另一个目录,想运行main function,输入python3 rec2sqlite ,得到如下output:

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

What do I need to change in the source code and/or the commands I use in order to be able to run the main function after installing the current version using pip ?在使用 pip 安装当前版本后,我需要更改源代码和/或我使用的命令才能运行pip

What happen when you run python3 rec2sqlite from inside the project directory?从项目目录中运行python3 rec2sqlite时会发生什么? If you have to run the it from another directory you could try with the full path to the directory python3 /<path-to-project-directory>/rec2sqlite如果您必须从另一个目录运行它,您可以尝试使用目录python3 /<path-to-project-directory>/rec2sqlite的完整路径

This answer helped.这个答案有帮助。 To fix the error, I had to do following:要修复错误,我必须执行以下操作:

  1. Put the main function code into the file __main__.py .将主要的 function 代码放入文件__main__.py中。
  2. Install the package using pip3 install.使用pip3 install. from the project directory.从项目目录。
  3. Use python3 -m <moduleName> (eg python3 -m rec2sqlite ) to run the program installed in step 2.使用python3 -m <moduleName> (例如python3 -m rec2sqlite )运行在步骤 2 中安装的程序。

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

相关问题 Python 用 Pip 和 Conda 安装后找不到模块 - Python Can't Find Module After Installing with Pip and Conda 使用 PIP 安装后,Windows 上的 Visual Code 找不到模块。 在终端窗口中使用了错误的 Python? - Visual Code on Windows can't find module after installing it with PIP. Using wrong Python in Terminal window? Python:使用pip安装xlrd后“导入错误:没有名为xlrd的模块” - Python: “ImportError: no module named xlrd” after installing xlrd using pip 使用pip安装后的Python“No Module named gTTS” - Python "No Module named gTTS" after installing it using pip pip安装google-cloud后找不到模块google_auth_httplib2。如何解决? - Module google_auth_httplib2 not found after pip installing google-cloud How can I fix it? 如何在不使用 pip 的情况下在 python 中添加 Discord 模块? - How can I add the Discord module in python without using pip? 使用 pip 安装后找不到 Python 3.9 模块 - Python 3.9 module not found after installing with pip 使用pip安装后无法导入模块 - Not able to import module after installing using pip 在python 2.7上使用pip安装后无法导入渲染 - I can't import render after installing with pip on python 2.7 使用pip安装Python模块 - Installing Python module with pip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM