如何直接 pip 查找setup.py?我的setup.py文件位于~/setuptools-3.5.1.
我跑了
dustin@dustin:~$ python setuptools-3.5.1/setup.py egg_info
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file 'setuptools.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'setuptools.egg-info/SOURCES.txt'
dustin@dustin:~$
Run Code Online (Sandbox Code Playgroud)
所以看起来一切都很好,但是当我运行 pip 时,我得到
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/matplotlib
Storing debug log for failure in /home/dustin/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)
我的印象是,当我运行 pip 时,它没有找到setup.py
one_file.py包含一些通用函数、类和main().
我想使用pip调用该函数的命令行脚本来安装它main()。
什么是目录结构并且setup.py可以做到这一点?
我最近安装了 pyenv,以便在每个项目的基础上在几个竞争的 python 解释器之间切换。因此,将入口点python setup.py develop放置在. 但是,从命令行调用这些脚本之一(例如:) 会导致错误:找不到该命令。console_script~/.pyenv/versions/3.4.3/bin$ my_entry_point_script
我该如何解决这个问题?$PATH这是、$PTHONPATH、 其他问题吗?作为参考,我的 shell (fish)status --is-interactive; and . (pyenv init -lpsub)在启动时执行。
编辑: 正确的解决方案将保持不同版本的 python 之间的清晰分离。
我正在尝试安装 subprocess32 python 模块(https://github.com/google/python-subprocess32),但 distutils 遇到一些问题。该模块包含必须构建的 C 扩展,但是当我运行 或 时,pip install .我python setup.py install得到以下输出:
...
creating build
creating build/temp.linux-x86_64-2.7
/non/existent/path/gcc -pthread -fPIC ... -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
unable to execute '/non/existent/path/gcc': No such file or directory
Run Code Online (Sandbox Code Playgroud)
显然,由于某种原因,distutils 使用了错误的 gcc 路径。然后我尝试使用手动指定 gcc 的正确路径export CC=/correct/path/to/gcc,得到以下输出:
building '_posixsubprocess' extension
creating build/temp.linux-x86_64-2.7
/correct/path/to/gcc -fPIC -fno-strict-aliasing -g -O2 ... -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
/non/existent/path/gcc -pthread -shared ... build/temp.linux-x86_64-2.7/_posixsubprocess.o -o build/lib.linux-x86_64-2.7/_posixsubprocess.so
unable to execute '/non/existent/path/gcc': No such file …Run Code Online (Sandbox Code Playgroud) 如果 python 包依赖于外部库,我们可以这样做:
from setuptools import setup
setup(name='funniest',
version='0.1',
description='The funniest joke in the world',
url='http://github.com/storborg/funniest',
author='Flying Circus',
author_email='flyingcircus@example.com',
license='MIT',
packages=['funniest'],
install_requires=[
'markdown',
],
zip_safe=False)
Run Code Online (Sandbox Code Playgroud)
如果我想安装一个包的预发布版本,install_requires我应该怎么做?我在 中找不到任何标志或命令setuptools,可以这样做吗?
安装不稳定的预发行版软件包的解决方案是什么install_requires?
我当前的 setup.py 将 git commit 哈希写入一个文件,模块在安装后可以访问该文件。但是,我想在开发模块时禁用它,因为 setup.py 文件不会被触发两次并且哈希值不准确。这给我们带来了一个问题:
有没有办法从 setup.py 判断模块是否以可编辑模式安装?IE,
Run Code Online (Sandbox Code Playgroud)pip install -e .
我在这里发现了一个类似的问题,但即使是“hack”在我的情况下也不起作用,因为模块将直接使用 git 安装,并且.git即使在安装过程中进行正常安装,该目录也会存在。
我正在尝试使用 pybind11 使用 C++ 编写的库在 python 中工作。
源文件的编译和构建工作没有错误,但使用 pip 安装时生成的文件会抛出此错误。
CMake Error at pybind11/tools/pybind11Tools.cmake:131 (add_library):
Cannot find source file:
../project/variables.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:5 (pybind11_add_module)
CMake Error at pybind11/tools/pybind11Tools.cmake:131 (add_library):
No SOURCES given to target: project
Call Stack (most recent call first):
CMakeLists.txt:5 (pybind11_add_module)
Run Code Online (Sandbox Code Playgroud)
我正在关注cmake_example并且我确信该文件存在。事实上,如果我删除该文件,运行时就会出现错误
python setup.py sdist
Run Code Online (Sandbox Code Playgroud)
文件夹结构是这样的:
C++ project root folder
|-- C++ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 构建一个 python 轮setuptools。该包需要包含两个文件:
mymodule.py- 与以下目录相同的 python 模块setup.pymyjar.jar- 存在于我的包目录之外的 java .jar 文件我正在使用 构建我的包python3 setup.py bdist_wheel。
如果我setup()这样调用:
setup(
name="mypkg",
py_modules=["mymodule"],
data_files=[('jars', ['../target/scala-2.11/myjar.jar'])]
)
Run Code Online (Sandbox Code Playgroud)
然后myjar.jar确实成功地包含在 .whl 中(到目前为止还不错),但是当我pip install mypkg将罐子放在/usr/local/myjar.jar(这有点解释了原因)时,这根本不是我想要的,我希望它存在于与 相同的位置mymodule.py,即/usr/local/lib/python3.7/site-packages/
如果我setup.py改为
setup(
name="mypkg",
py_modules=["mymodule"],
package_data={'jars': '../target/scala-2.11/myjar.jar'}
)
Run Code Online (Sandbox Code Playgroud)
或者
setup(
name="mypkg",
py_modules=["mymodule"],
package_data={'jars': ['../target/scala-2.11/myjar.jar']}
)
Run Code Online (Sandbox Code Playgroud)
那么myjar.jar根本不包含在 .whl 中。我尝试复制myjar.jar到同一目录并更改setup.py为:
setup(
name="mypkg",
py_modules=["mymodule"],
package_data={'jars': 'myjar.jar'} …Run Code Online (Sandbox Code Playgroud) 如果我安装两个具有相同顶级目录级别名称但不同包名称(由 setup.py 或其他识别方法定义)的 python 包,会发生冲突还是“命名空间”会被合并?
例如,如果我有以下结构:
repo1
mypkg/
__init__.py
compiler/...
setup.cfg -> name=repo1
repo2
mypkg/
__init__.py
runner/...
setup.cfg -> name=repo2
Run Code Online (Sandbox Code Playgroud)
我可以安装这两个而不发生冲突吗?如果是,我可以像这样导入它们吗:
from mypkg.runner import *
from mypkg.compiler import *
Run Code Online (Sandbox Code Playgroud) 根据我的研究,以下应该有效:
from setuptools import setup
from setuptools import find_packages
...
REQUIRES_INSTALL = [
'spacy==2.3.2',
'tensorflow==1.14.0',
'Keras==2.2.4',
'keras-contrib@git+https://github.com/keras-team/keras-contrib.git#egg=keras-contrib',
'en-core-web-sm@https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.0/en_core_web_sm-2.3.0.tar.gz#egg=en-core-web-sm'
]
...
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
install_requires=REQUIRES_INSTALL,
...
)
Run Code Online (Sandbox Code Playgroud)
当建造轮子或鸡蛋时,一切都很好:python setup.py bdist_wheel。
但是当尝试使用pip install -U dist/mypack-....whl.
我得到:
ERROR: Could not find a version that satisfies the requirement keras-contrib (from mypack==0.3.5) (from versions: none)
ERROR: No matching distribution found for keras-contrib (from mypack==0.3.5)
...
ERROR: Could not find a version that satisfies the requirement en-core-web-sm (from mypack==0.3.5) (from versions: …Run Code Online (Sandbox Code Playgroud)