这可能是一个跟进的问题这一个.
我正在使用setuptools来安装我的包.作为依赖,我列出了numpy.我正在使用Python2.7,当我这样做
python setup.py install
Run Code Online (Sandbox Code Playgroud)
用这个setup.py文件:
from setuptools import setup
setup(name = "test_pack", install_requires = ["numpy"])
Run Code Online (Sandbox Code Playgroud)
我最终得到此错误消息:
ImportError: No module named numpy.distutils
Run Code Online (Sandbox Code Playgroud)
为了包含numpy作为依赖项并在未安装的情况下安装它,我需要做什么python-dev?
完整输出python setup.py install:
running install
running bdist_egg
running egg_info
writing requirements to test_pack.egg-info/requires.txt
writing test_pack.egg-info/PKG-INFO
writing top-level names to test_pack.egg-info/top_level.txt
writing dependency_links to test_pack.egg-info/dependency_links.txt
reading manifest file 'test_pack.egg-info/SOURCES.txt'
writing manifest file 'test_pack.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/test_pack …Run Code Online (Sandbox Code Playgroud) Anaconda在科学计算领域非常受欢迎,因为它将超过125种最广泛使用的Python数据分析库捆绑在一起.我的问题是,既然我们已经有了pip(这是一个非常广泛使用的Python包管理器),为什么我们需要Anaconda呢?难道我们都不能pip install为125个以上的图书馆中的每个图书馆打字而且他们都能很好地合作吗?或者他们不能很好地合作,这意味着Anaconda通过整理出来试图让125个以上的图书馆进行良好互动时出现的问题,帮助了我们所有人?
我正在尝试创建一个setup.py依赖于SciPy的项目.以下setup.py重现:
setup(
name='test',
version='0.1',
install_requires=['scipy']
)
Run Code Online (Sandbox Code Playgroud)
使用python setup.py develop它安装时会生成以下错误:
ImportError: No module named numpy.distutils.core
Run Code Online (Sandbox Code Playgroud)
但是,当我安装scipy时pip,它是从一个轮子安装它,它工作得很好.
所以,我的问题是,我如何创建一个setup.py取决于SciPy?为什么不setuptools安装轮子的依赖?使用Python 3时这会更好吗(我们计划无论如何都要迁移,所以如果它在那里工作,我会等到迁移完成后).
我在Mac OS X 10.10.1上使用Python 2.7.8 setuptools3.6和pip1.5.6.
我想创建一个setup.py文件,自动将构建时依赖项解析为numpy(用于编译扩展).我的第一个猜测是使用setup_requires和子类化命令类来导入numpy模块:
from setuptools import setup, Extension
from distutils.command.build import build as _build
class build(_build):
def run(self):
import numpy
print(numpy.get_include())
_build.run(self)
setup(
name='test',
version='0.0',
description='something',
cmdclass={'build':build},
setup_requires=['numpy'],
)
Run Code Online (Sandbox Code Playgroud)
现在,运行python setup.py build成功编译numpy但然后失败(内部build.run):
AttributeError: 'module' object has no attribute 'get_include'
Run Code Online (Sandbox Code Playgroud)
但是,如果再次运行相同的命令,该命令现在成功(并且不需要重新编译numpy).
我已经在python {2.6,2.7,3.3}上使用和不使用virtualenv在最新版本的setuptools上进行了测试.
我已经看到使用pkg_resources.resource_filename的解决方法似乎工作得很好,如果我们想要的只是include目录.编辑:只适用于python2!
但是,我现在很好奇.使用setup_requires有什么警告?可能是因为numpy无法正常工作的原因是什么?对于一些更简单的模块,它似乎没有问题.
我目前正在开发一个使用cython和的python包,numpy并且我希望使用pip install干净的python安装中的命令来安装包.应自动安装所有依赖项.我正在使用setuptools以下内容setup.py:
import setuptools
my_c_lib_ext = setuptools.Extension(
name="my_c_lib",
sources=["my_c_lib/some_file.pyx"]
)
setuptools.setup(
name="my_lib",
version="0.0.1",
author="Me",
author_email="me@myself.com",
description="Some python library",
packages=["my_lib"],
ext_modules=[my_c_lib_ext],
setup_requires=["cython >= 0.29"],
install_requires=["numpy >= 1.15"],
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent"
]
)
Run Code Online (Sandbox Code Playgroud)
到目前为止,这一点很有效.该pip install命令下载cython了该构建,并能够构建我的包并与其一起安装numpy.
现在我想提高cython代码的性能,这会导致我的代码发生一些变化setup.py.我需要添加include_dirs=[numpy.get_include()]调用setuptools.Extension(...)或setuptools.setup(...)哪些意味着我还需要import numpy.(请参阅http://docs.cython.org/en/latest/src/tutorial/numpy.html并让distutils在正确的位置查找numpy头文件.)
这是不好的.现在用户无法pip install从干净的环境中调用,因为 …
我一直在努力创建一个python包,其中包含一些我想在numpy中使用f2py合并的fortran代码.目标是将其上传到PyPI,以便用户可以使用pip进行安装.我做了一些研究,发现setuptools和numpy.distutils.core具有我想要的功能(我认为).包的结构如下,
rabacus
--setup.py
--README.txt
--MANIFEST.in
--rabacus
----f2py
----python_mod1
----python_mod2
----python_mod3
Run Code Online (Sandbox Code Playgroud)
我在目录f2py中有fortran代码.我的包需要numpy和另一个名为quantity的python包,这两个包都在PyPI中.我已经使用install_requires关键字向setup函数指出了这一点.我的测试周期是这样的,
注册并上传包到PyPI
python setup.py register sdist upload
Run Code Online (Sandbox Code Playgroud)
创建一个没有系统包的虚拟环境
virtualenv --no-site-packages venv
Run Code Online (Sandbox Code Playgroud)
进入虚拟环境并尝试使用pip进行安装
cd venv/bin
./pip install rabacus
Run Code Online (Sandbox Code Playgroud)
我想要检测未满足的要求(numpy和数量),下载它们然后继续我的包安装.我很困惑我应该调用哪个设置函数(来自setuptools的那个或来自numpy.distutils.core的那个).似乎有一个有install_requires,一个有ext_modules.到目前为止,当我在虚拟环境中执行pip命令时,我得到一个错误,抱怨找不到numpy
Downloading/unpacking rabacus
Downloading rabacus-0.9.0.tar.gz (1.7MB): 1.7MB downloaded
Running setup.py egg_info for package rabacus
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/galtay/bitbucket/rabacus/venv/build/rabacus/setup.py", line 3, in <module>
import numpy.distutils.core
ImportError: No module named numpy.distutils.core
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line …Run Code Online (Sandbox Code Playgroud) python ×5
setuptools ×5
numpy ×4
python-2.7 ×2
anaconda ×1
cython ×1
f2py ×1
pip ×1
python-3.x ×1
scipy ×1