Python.网络分布与我的应用程序:在线或离线安装?



我正在寻找一些关于分发Python的最佳方法的建议。Net和我的申请。看来我有两个选择:

1。我的应用程序安装程序运行pip install pythonnet

缺点是客户需要在安装时连接互联网。

2。捆绑Python。Net文件与我的应用程序允许离线安装

我喜欢一个可以离线运行的"独立"安装程序的想法,但是这是一个好主意吗?它需要安装正确版本的Python。. Net与客户安装的Python版本匹配。

我尝试了以下步骤:

C:mkdir download pythonnet
cd download pythonnet
pip download pythonnet     <-- this gets two files: pythonnet-2.5.2.tar.gz and pycparser-2.20-py2.py3-none-any.whl
<disconnect from the internet>
pip install C:pythonnet_downloadpythonnet-2.5.2.tar.gz
然而,这会给出错误:
Processing c:pythonnet_downloadpythonnet-2.5.2.tar.gz
Requirement already satisfied: pycparser in c:program filespython39libsite-packages (from pythonnet==2.5.2) (2.20)
Building wheels for collected packages: pythonnet
Building wheel for pythonnet (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'c:program filespython39python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"'; __file__='"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:UsersvincluffAppDataLocalTemppip-wheel-s9qap8ze'
cwd: C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76
Complete output (44 lines):
running bdist_wheel
running build
running build_ext
Checking for updates from https://www.nuget.org/api/v2/.
The remote name could not be resolved: 'www.nuget.org'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76setup.py", line 630, in <module>
setup(
File "c:program filespython39libsite-packagessetuptools__init__.py", line 165, in setup
return distutils.core.setup(**attrs)
File "c:program filespython39libdistutilscore.py", line 148, in setup
dist.run_commands()
File "c:program filespython39libdistutilsdist.py", line 966, in run_commands
self.run_command(cmd)
File "c:program filespython39libdistutilsdist.py", line 985, in run_command
cmd_obj.run()
File "C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76setup.py", line 612, in run
return bdist_wheel.bdist_wheel.run(self)
File "C:UsersvincluffAppDataRoamingPythonPython39site-packageswheelbdist_wheel.py", line 290, in run
self.run_command('build')
File "c:program filespython39libdistutilscmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:program filespython39libdistutilsdist.py", line 985, in run_command
cmd_obj.run()
File "c:program filespython39libdistutilscommandbuild.py", line 135, in run
self.run_command(cmd_name)
File "c:program filespython39libdistutilscmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:program filespython39libdistutilsdist.py", line 985, in run_command
cmd_obj.run()
File "c:program filespython39libdistutilscommandbuild_ext.py", line 340, in run
self.build_extensions()
File "c:program filespython39libdistutilscommandbuild_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "c:program filespython39libdistutilscommandbuild_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76setup.py", line 249, in build_extension
self._install_packages()
File "C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76setup.py", line 438, in _install_packages
subprocess.check_call(cmd, shell=use_shell)
File "c:program filespython39libsubprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'toolsnugetnuget.exe update -self' returned non-zero exit status 1.
----------------------------------------
ERROR: Failed building wheel for pythonnet
Running setup.py clean for pythonnet
Failed to build pythonnet
Installing collected packages: pythonnet
Running setup.py install for pythonnet ... error
ERROR: Command errored out with exit status 1:
command: 'c:program filespython39python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"'; __file__='"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersvincluffAppDataLocalTemppip-record-lcx9op7pinstall-record.txt' --single-version-externally-managed --compile --install-headers 'c:program filespython39Includepythonnet'
cwd: C:UsersvincluffAppDataLocalTemppip-req-build-bgue1v76
Complete output (6 lines):
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: option --single-version-externally-managed not recognized
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:program filespython39python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"'; __file__='"'"'C:\Users\vincluff\AppData\Local\Temp\pip-req-build-bgue1v76\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersvincluffAppDataLocalTemppip-record-lcx9op7pinstall-record.txt' --single-version-externally-managed --compile --install-headers 'c:program filespython39Includepythonnet' Check the logs for full command output
  • 为什么以上步骤失败?
  • 如果我让这个工作,它将允许创建一个Python。网轮哪个匹配安装的Python版本?

注意:我能够通过以下步骤获得离线安装工作,但这是使用特定于我安装的Python版本的轮子。我希望它能与客户拥有的任何Python版本一起工作。

pip install pythonnet
< search in C:UsersvinceAppDataLocalpipcachewheels for pythonnet-2.5.2-cp39-cp39-win_amd64.whl and copy it to C:copy_of_pythonnet_wheel >
pip uninstall pythonnet
pip install C:copy_of_pythonnet_wheelpythonnet-2.5.2-cp39-cp39-win_amd64.whl

Python.Runtime.dll相关问题:

如果我使用在线安装程序(pip install pythonnet),它会将Python.Runtime.dll放在site-packages目录中,例如:C:Program FilesPython39Lib site-packages。我的。net应用程序应该加载这个Python.Runtime.dll,还是应该使用我编译我的。net项目所针对的Python.Runtime.dll,因此已经安装在C:Program Files MyDotNetExeLocation中?

如果是前者,我如何指定Python.Runtime.dll的位置?位置取决于用户决定在哪里安装Python,所以我不知道在哪里找到它。我能想到的一个解决方案是:在我的安装程序安装了Python之后。Net,它检查站点包的位置使用:

py.exe -c "import site; print(next(item for item in site.getsitepackages() if 'site-packages' in item))"

然后从这个目录复制Python.Runtime.dll到C:Program Files MyDotNetExeLocation

即将推出的Python。不需要使用pip安装。NET 3.0来启用Python嵌入到。NET项目中。你可以从GitHubsrc/runtime目录构建它,或者从NuGet.org获取最新的每月预览版本。

你的应用程序需要将Runtime.PythonDLL设置为python39.dllPythonEngine.PythonHome到Python主目录的完整路径(在Windows上通常是python39.dll所在的目录)。

相关内容

  • 没有找到相关文章

最新更新