简体   繁体   English

pip安装后找不到包

[英]Package not found after pip install

I've published a module to PyPi using Flit: a2d_diary (I've checked that the tar.gz contains all the scripts). 我已经使用Flit将模块发布到PyPi: a2d_diary (我检查了tar.gz是否包含所有脚本)。

Then, I tried to install it in a virtual env in Windows and Linux using pip install a2d_diary and although it works and all dependencies are installed, if I try to run a2d_diary in a terminal (with the venv activate) it does not find my package. 然后,我尝试使用pip install a2d_diary在Windows和Linux中的虚拟环境中pip install a2d_diary ,尽管它可以工作并且安装了所有依赖项,但是如果我尝试在终端中运行a2d_diary (使用venv激活),它将找不到我的软件包。

Is this a problem with Flit, PyPi or am I missing something in the main script? 这是Flit,PyPi的问题,还是我在主脚本中缺少某些内容? The source code is here 源代码在这里

Thanks! 谢谢!

The file a2d_diary.py is installed, but it won't be accessible via running $ ad2_diary.py from your terminal. 已安装文件a2d_diary.py ,但无法从终端运行$ ad2_diary.py进行访问。 These are the package files that were installed: 这些是已安装的软件包文件:

$ pip show -f a2d_diary
Name: a2d-diary
Version: 0.1
Summary: A2D-Diary web app. Create and encode paper diaries 
automatically
Home-page: https://a2d-diary.netlify.com
Author: Julio Vega
Author-email: julio.vega@protonmail.com
License: UNKNOWN
Location: /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages
Requires: PyPDF2, numpy, waitress, opencv-python, reportlab, falcon-multipart, falcon, Pillow
Files:
  __pycache__/a2d_diary.cpython-36.pyc
  a2d_diary-0.1.dist-info/INSTALLER
  a2d_diary-0.1.dist-info/LICENSE
  a2d_diary-0.1.dist-info/METADATA
  a2d_diary-0.1.dist-info/RECORD
  a2d_diary-0.1.dist-info/WHEEL
  a2d_diary.py

If you want the script to be executable after the installation, you have to declare it as such in the package setup file (btw, I don't see any setup.py in your repository - did you commit it?). 如果希望脚本在安装后可执行,则必须在程序包安装文件中声明该脚本(顺便说一句,我在存储库中看不到任何setup.py您提交了吗?)。 Example setup.py : 示例setup.py

from setuptools import setup, find_packages

setup(
    name='a2d_diary',
    version='0.1',
    packages=find_packages(where='src'),
    package_dir={
        '': 'src',
    },
    scripts=['src/a2d_diary.py'],
)

Another thing you will need in order to make your a2d_diary.py script executable is the shebang line (works for Unix, no idea what to do on Windows since I don't do Windows at all): first line in a2d_diary.py should be 为了使a2d_diary.py脚本可执行文件,您需要执行的另一件事是shebang行(适用于Unix,由于我根本不使用Windows,所以不知道在Windows上应a2d_diary.py ): a2d_diary.py第一行应为

#!/usr/bin/env python

if your script can be run with any version of Python or 如果您的脚本可以使用任何版本的Python或

#!/usr/bin/env python3

for Python 3 specifically or 专门针对Python 3或

#!/usr/bin/env python2

for Python 2 specifically. 专门针对Python 2。

Now, if you build a wheel or source tar and install it, you will be able to run the script via 现在,如果您构建了转轮或源tar并安装了它,则可以通过以下方式运行脚本

$ a2d_diary.py

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM