在没有互联网访问的情况下安装 pythonnet

Installing pythonnet with no internet access

我正在尝试在无法访问 Internet 的计算机上安装 pythonnet。在连接的机器上,我从 Github 下载了 pythonnet-master.zip,从 pypi.

下载了 pythonnet-2.4.0.tar.gz

当我尝试 pip install pythonnet-2.4.0.tar.gz 时,出现错误 The remote name could not be resolved: 'www.nuget.org.

然后我用 conda install nuget-3.2.0.10516-py34_0.tar.bz2 来处理 nuget。安装成功,但是还是安装不了pythonnet

我尝试使用 pythonnet-master.zip 和 conda install 也失败了。任何想法都会有所帮助。

这是完整的错误输出:

(raman_env) C:\Users\Administrator\Desktop\eric\software>pip install pythonnet-2
.4.0.tar.gz
Processing c:\users\administrator\desktop\eric\software\pythonnet-2.4.0.tar.gz
Building wheels for collected packages: pythonnet
  Building wheel for pythonnet (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\ProgramData\Anaconda3\envs\raman_env\python.exe' -u -c 'import s
ys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ADMINI~1\AppData\Local
\Temp\pip-req-build-8jks801m\setup.py'"'"'; __file__='"'"'C:\Users\ADMINI~1
\AppData\Local\Temp\pip-req-build-8jks801m\setup.py'"'"';f=getattr(tokenize
, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'
"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C
:\Users\ADMINI~1\AppData\Local\Temp\pip-wheel-vi5w5zft' --python-tag cp37
       cwd: C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\
  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:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py",
 line 658, in <module>
      zip_safe=False,
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\site-packages\setuptools\_
_init__.py", line 145, in setup
      return distutils.core.setup(**attrs)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\core.py", line 1
48, in setup
      dist.run_commands()
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\dist.py", line 9
66, in run_commands
      self.run_command(cmd)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\dist.py", line 9
85, in run_command
      cmd_obj.run()
    File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py",
 line 610, in run
      return bdist_wheel.bdist_wheel.run(self)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\site-packages\wheel\bdist_
wheel.py", line 192, in run
      self.run_command('build')
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\cmd.py", line 31
3, in run_command
      self.distribution.run_command(command)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\dist.py", line 9
85, in run_command
      cmd_obj.run()
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\command\build.py
", line 135, in run
      self.run_command(cmd_name)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\cmd.py", line 31
3, in run_command
      self.distribution.run_command(command)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\dist.py", line 9
85, in run_command
      cmd_obj.run()
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\command\build_ex
t.py", line 340, in run
      self.build_extensions()
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\command\build_ex
t.py", line 449, in build_extensions
      self._build_extensions_serial()
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\distutils\command\build_ex
t.py", line 474, in _build_extensions_serial
      self.build_extension(ext)
    File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py",
 line 245, in build_extension
      self._install_packages()
    File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py",
 line 424, in _install_packages
      subprocess.check_call(cmd, shell=use_shell)
    File "C:\ProgramData\Anaconda3\envs\raman_env\lib\subprocess.py", line 347,
in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command 'tools\nuget\nuget.exe update -self' re
turned 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:\ProgramData\Anaconda3\envs\raman_env\python.exe' -u -c 'import
 sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ADMINI~1\AppData\Loc
al\Temp\pip-req-build-8jks801m\setup.py'"'"'; __file__='"'"'C:\Users\ADMINI
~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py'"'"';f=getattr(tokeni
ze, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\
n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --recor
d 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-31isrm6o\install-record.txt'
--single-version-externally-managed --compile
         cwd: C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\
    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:\ProgramData\Anaconda3\envs\ra
man_env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'
C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801m\setup.py'"'"'
; __file__='"'"'C:\Users\ADMINI~1\AppData\Local\Temp\pip-req-build-8jks801
m\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read
().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__,
'"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-rec
ord-31isrm6o\install-record.txt' --single-version-externally-managed --compile C
heck the logs for full command output.

pythonnetsetup.py 正在尝试 运行 nugget.exe update --self 由于缺少互联网连接,您的系统失败了。我可以想到两种可能的解决方案:

  1. 尝试下载正确的 whl 文件,而不是源安装。在pypi上,只有cp37及以下的。如果你是运行ning pyhton 3.8,可以找到合适的wheel文件here

  2. 提取 tar.gz 存档和注释行 424:subprocess.check_call(cmd, shell=use_shell)。然后运行python setup.py install。这将防止安装程序在安装过程中尝试更新 nugget