使用setuptools和pip.main安装软件包

时间:2017-11-14 15:16:43

标签: python numpy pip setuptools setup.py

我正在尝试为python包创建一个安装脚本。为了便于设置,我希望使用setuptools安装所有依赖项。但是,我在以这种方式安装这些软件包时遇到了一些困难:let viewControllerShown = app.otherElements["view_myviewcontroller"].waitForExistence(timeout: 5) XCTAssert(viewControllerShown) let instructionViewExists = app.staticTexts["pushNotificationInstruction"].exists XCTAssertFalse(instructionViewExists) numpymatplotlibscipynetcdf4pandas。已经在SO postmatplotlib herepandas herescipy here中询问了numpy问题。所以看起来这是一个反复出现的问题,虽然我找到了每个这样的软件包的解决方法,即在安装脚本中使用pymatgen

pip

问题是,当另一个包需要这个包时,调用pip来安装依赖项的事实,setuptools会引发一个奇怪的SandBoxViolation错误,它会阻止使用pip.main函数。 这是一个示例回溯:

from setuptools import pip
import pip

for package in ("numpy", "matplotlib", "scipy", "netcdf4", "pandas",
                "pymatgen"):
    pip.main(["install", package])

setup(name="package_name",
      ...)

解决方法是对此程序包使用Traceback (most recent call last): File ".../lib/python3.6/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File ".../lib/python3.6/site-packages/pip/commands/install.py", line 335, in run wb.build(autobuilding=True) File ".../lib/python3.6/site-packages/pip/wheel.py", line 749, in build self.requirement_set.prepare_files(self.finder) File ".../lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies)) File ".../lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file require_hashes File ".../lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link self.link = finder.find_requirement(self, upgrade) File ".../lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement all_candidates = self.find_all_candidates(req.name) File ".../lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates for page in self._get_pages(url_locations, project_name): File ".../lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages page = self._get_page(location) File ".../lib/python3.6/site-packages/pip/index.py", line 683, in _get_page return HTMLPage.get_page(link, session=self.session) File ".../lib/python3.6/site-packages/pip/index.py", line 792, in get_page "Cache-Control": "max-age=600", File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 488, in get return self.request('GET', url, **kwargs) File ".../lib/python3.6/site-packages/pip/download.py", line 386, in request return super(PipSession, self).request(method, url, *args, **kwargs) File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request resp = self.send(prep, **send_kwargs) File ".../lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send r = adapter.send(request, **kwargs) File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/adapter.py", line 37, in send cached_response = self.controller.cached_request(request) File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/controller.py", line 202, in cached_request self.cache.delete(cache_url) File ".../lib/python3.6/site-packages/pip/download.py", line 302, in delete return super(SafeFileCache, self).delete(*args, **kwargs) File ".../lib/python3.6/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py", line 107, in delete os.remove(name) File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 314, in wrap path = self._remap_input(name, path, *args, **kw) File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 456, in _remap_input self._violation(operation, os.path.realpath(path), *args, **kw) File ".../lib/python3.6/site-packages/setuptools/sandbox.py", line 411, in _violation raise SandboxViolation(operation, args, kw) setuptools.sandbox.SandboxViolation: SandboxViolation: remove('/.../Library/Caches/pip/http/8/f/4/a/1/8f4a19894a92f9 63886c9b755abcf90542da3c3c8283d3bebe3650b2',) {} The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted. This package cannot be safely installed by EasyInstall, and may not support alternate installation locations even if you run its setup script by hand. Please inform the package's author and the EasyInstall maintainers to find out if a fix or workaround is available. 方法... 所以我得出结论,应该避免使用pip.main函数,但我不知道安装有问题的依赖项的简单方法。所以我的问题是:如何处理有问题的依赖项,例如pip.mainnumpyscipy等,以便自动安装它们(没有pymatgen,只需使用setuptools例如)?如果无法避免使用pip,那么应该如何安装在其设置中调用pip的包(为了避免SandboxViolation错误)?

0 个答案:

没有答案