如何安装src-0.0.7包?

Edw*_*. Y 0 python pip

我正在构建一个运行代码的环境,代码“import src”不在colab或我的电脑中。我看到了 PyPl 页面,它说我应该运行“pip install src”,但我仍然无法成功。

(base) oblic@oblic-PC:~$ pip install src
Collecting src
  Using cached src-0.0.7.zip (6.3 kB)
Building wheels for collected packages: src
  Building wheel for src (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/oblic/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qffzaygw/src/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qffzaygw/src/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 /tmp/pip-wheel-m62_ocqn
       cwd: /tmp/pip-install-qffzaygw/src/
  Complete output (41 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/src
  copying src/__init__.py -> build/lib/src
  running egg_info
  writing src.egg-info/PKG-INFO
  writing dependency_links to src.egg-info/dependency_links.txt
  writing entry points to src.egg-info/entry_points.txt
  writing requirements to src.egg-info/requires.txt
  writing top-level names to src.egg-info/top_level.txt
  reading manifest file 'src.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'src.egg-info/SOURCES.txt'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-qffzaygw/src/setup.py", line 96, in <module>
      'install_lib': InstallCommand,
    File "/home/oblic/anaconda3/lib/python3.7/site-packages/setuptools/__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "/home/oblic/anaconda3/lib/python3.7/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/oblic/anaconda3/lib/python3.7/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/home/oblic/anaconda3/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/home/oblic/anaconda3/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 226, in run
      reinit_subcommands=True)
    File "/home/oblic/anaconda3/lib/python3.7/site-packages/setuptools/__init__.py", line 198, in reinitialize_command
      cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
    File "/home/oblic/anaconda3/lib/python3.7/distutils/cmd.py", line 306, in reinitialize_command
      reinit_subcommands)
    File "/home/oblic/anaconda3/lib/python3.7/distutils/dist.py", line 950, in reinitialize_command
      for sub in command.get_sub_commands():
    File "/home/oblic/anaconda3/lib/python3.7/distutils/cmd.py", line 324, in get_sub_commands
      if method is None or method(self):
    File "/home/oblic/anaconda3/lib/python3.7/distutils/command/install.py", line 631, in has_lib
      return (self.distribution.has_pure_modules() or
  AttributeError: 'NoneType' object has no attribute 'has_pure_modules'
  ----------------------------------------
  ERROR: Failed building wheel for src
  Running setup.py clean for src
Failed to build src
Installing collected packages: src
    Running setup.py install for src ... error
    ERROR: Command errored out with exit status 1:
     command: /home/oblic/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qffzaygw/src/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qffzaygw/src/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4y4re6aq/install-record.txt --single-version-externally-managed --compile --install-headers /home/oblic/anaconda3/include/python3.7m/src
         cwd: /tmp/pip-install-qffzaygw/src/
    Complete output (2 lines):
    running install
    You've probably made a mistake here and are trying to install from a 'src' directory which doesn't exist.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/oblic/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qffzaygw/src/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qffzaygw/src/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4y4re6aq/install-record.txt --single-version-externally-managed --compile --install-headers /home/oblic/anaconda3/include/python3.7m/src Check the logs for full command output.

Run Code Online (Sandbox Code Playgroud)

上面是我尝试设置包“src”时的输出。我不知道我是否可以发布这个。

Edw*_*. Y 5

谢谢你们大家。你真的帮助我弄清楚了问题是什么。现在让我澄清一下,希望这个案例可以帮助其他人。

我想要运行的代码实际上包含在名为“src”的字典中。程序员编写了他们的代码,例如 main.py,其中包含以下行: ''' import src.utils as utils ''' 我犯了一个错误,我在 ~/main/src 字典中运行了代码,所以 python 返回错误“没有 src 模块”。然后我就傻傻的找到了src包。

实际上,运行代码的一种简单方法是将所有 .py 文件复制到上层字典,在我的例子中是 ~/main/,并在 ~/main/ 中运行 main.py,因为 ~/main/src/ 包含 utils .py,那么代码就会顺利运行,并且不会丢失任何模块。

  • 也许,现在你应该接受自己的答案,因为它确实很有帮助。 (2认同)