<p>virtualenv --always-copy 在 CentOS 上失败(lib64 问题?)</p>

创建于 2019-03-05  ·  12评论  ·  资料来源: pypa/virtualenv

在使用/lib64目录的平台上使用--always-copy创建 virtualenv 似乎是不可能的。

在 CentOS 7.6 上,系统包(python 2.7.5 、virtualenv 15.1.0 )和通过 SCL 安装的包都会发生同样的情况。
有一些可能相关的票证(#985、#1192、#3477、https://github.com/FPGAwars/icestudio/issues/244),以及据称可以解决问题的合并拉取请求(#1189),但我的印象是仍然有一些错误发生。

使用 SCL 的示例(Python 3.6.3 ,virtualenv 手动升级到16.4.3 )。
第一个错误似乎发生在virtualenv_support/pip-19.0.3-py2.py3-none-any.whl

  File "<scl_base>/lib64/python3.6/socket.py", line 49, in <module>
    import _socket
ModuleNotFoundError: No module named '_socket'

完整的日志以在上下文中查看它。

$ <scl_base>/bin/virtualenv --python <scl_base>/bin/python --always-copy --verbose TEST
Running virtualenv with interpreter <scl_base>/bin/python
Using base prefix '<scl_base>'
Creating <somedir>/TEST/lib/python3.6
Copying to <somedir>/TEST/lib64
Symlinking Python bootstrap modules
  Copying to <somedir>/TEST/lib/python3.6/config-3.6m-x86_64-linux-gnu
  Copying to <somedir>/TEST/lib/python3.6/lib-dynload
  Copying to <somedir>/TEST/lib64/python3.6/os.py
  Ignoring built-in bootstrap module: posix
  Copying to <somedir>/TEST/lib64/python3.6/posixpath.py
  Cannot import bootstrap module: nt
  Copying to <somedir>/TEST/lib64/python3.6/ntpath.py
  Copying to <somedir>/TEST/lib64/python3.6/genericpath.py
  Copying to <somedir>/TEST/lib64/python3.6/fnmatch.py
  Copying to <somedir>/TEST/lib64/python3.6/locale.py
  Copying to <somedir>/TEST/lib64/python3.6/encodings
  Copying to <somedir>/TEST/lib64/python3.6/codecs.py
  Copying to <somedir>/TEST/lib64/python3.6/stat.py
  Cannot import bootstrap module: UserDict
  Creating parent directories for <somedir>/TEST/lib64/python3.6/lib-dynload
  Copying to <somedir>/TEST/lib64/python3.6/lib-dynload/readline.cpython-36m-x86_64-linux-gnu.so
  Cannot import bootstrap module: copy_reg
  Copying to <somedir>/TEST/lib64/python3.6/types.py
  Copying to <somedir>/TEST/lib64/python3.6/re.py
  Cannot import bootstrap module: sre
  Copying to <somedir>/TEST/lib64/python3.6/sre_parse.py
  Copying to <somedir>/TEST/lib64/python3.6/sre_constants.py
  Copying to <somedir>/TEST/lib64/python3.6/sre_compile.py
  Copying to <somedir>/TEST/lib64/python3.6/lib-dynload/zlib.cpython-36m-x86_64-linux-gnu.so
  Cannot import bootstrap module: _abcoll
  Copying to <somedir>/TEST/lib64/python3.6/warnings.py
  Copying to <somedir>/TEST/lib64/python3.6/linecache.py
  Copying to <somedir>/TEST/lib64/python3.6/abc.py
  Copying to <somedir>/TEST/lib64/python3.6/io.py
  Copying to <somedir>/TEST/lib64/python3.6/_weakrefset.py
  Copying to <somedir>/TEST/lib64/python3.6/copyreg.py
  Copying to <somedir>/TEST/lib64/python3.6/tempfile.py
  Copying to <somedir>/TEST/lib64/python3.6/random.py
  Copying to <somedir>/TEST/lib64/python3.6/__future__.py
  Copying to <somedir>/TEST/lib64/python3.6/collections
  Copying to <somedir>/TEST/lib64/python3.6/keyword.py
  Copying to <somedir>/TEST/lib64/python3.6/tarfile.py
  Copying to <somedir>/TEST/lib64/python3.6/shutil.py
  Copying to <somedir>/TEST/lib64/python3.6/struct.py
  Copying to <somedir>/TEST/lib64/python3.6/copy.py
  Copying to <somedir>/TEST/lib64/python3.6/tokenize.py
  Copying to <somedir>/TEST/lib64/python3.6/token.py
  Copying to <somedir>/TEST/lib64/python3.6/functools.py
  Copying to <somedir>/TEST/lib64/python3.6/heapq.py
  Copying to <somedir>/TEST/lib64/python3.6/bisect.py
  Copying to <somedir>/TEST/lib64/python3.6/weakref.py
  Copying to <somedir>/TEST/lib64/python3.6/reprlib.py
  Copying to <somedir>/TEST/lib64/python3.6/base64.py
  Copying to <somedir>/TEST/lib64/python3.6/_dummy_thread.py
  Copying to <somedir>/TEST/lib64/python3.6/hashlib.py
  Copying to <somedir>/TEST/lib64/python3.6/hmac.py
  Copying to <somedir>/TEST/lib64/python3.6/imp.py
  Copying to <somedir>/TEST/lib64/python3.6/importlib
  Copying to <somedir>/TEST/lib64/python3.6/rlcompleter.py
  Copying to <somedir>/TEST/lib64/python3.6/operator.py
  Copying to <somedir>/TEST/lib64/python3.6/_collections_abc.py
  Copying to <somedir>/TEST/lib64/python3.6/_bootlocale.py
  Copying to <somedir>/TEST/lib64/python3.6/enum.py
  No LICENSE.txt / LICENSE found in source
Creating <somedir>/TEST/lib/python3.6/site-packages
Writing <somedir>/TEST/lib64/python3.6/site.py
Writing <somedir>/TEST/lib64/python3.6/orig-prefix.txt
Writing <somedir>/TEST/lib64/python3.6/no-global-site-packages.txt
Creating <somedir>/TEST/bin
New python executable in <somedir>/TEST/bin/python
Changed mode of <somedir>/TEST/bin/python to 0o775
Copying to <somedir>/TEST/bin/python3
Copying to <somedir>/TEST/bin/python3.6
Testing executable with <somedir>/TEST/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
Got sys.prefix result: '<somedir>/TEST'
Creating <somedir>/TEST/lib64/python3.6/distutils
Writing <somedir>/TEST/lib64/python3.6/distutils/__init__.py
Writing <somedir>/TEST/lib64/python3.6/distutils/distutils.cfg
Traceback (most recent call last):
  File "<scl_base>/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "<scl_base>/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/__main__.py", line 16, in <module>
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 19, in <module>
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/urllib3/__init__.py", line 8, in <module>
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
  File "<scl_base>/lib64/python3.6/socket.py", line 49, in <module>
    import _socket
ModuleNotFoundError: No module named '_socket'
Command <somedir>/TEST/bin/python -m pip config list had error code 1
Installing setuptools, pip, wheel...

  Traceback (most recent call last):
    File "<stdin>", line 4, in <module>
    File "<somedir>/TEST/lib64/python3.6/tempfile.py", line 45, in <module>
      from random import Random as _Random
    File "<somedir>/TEST/lib64/python3.6/random.py", line 42, in <module>
      from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
  ModuleNotFoundError: No module named 'math'
  Complete output from command <somedir>/TEST/bin/python - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "<somedir>/TEST/lib64/python3.6/tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "<somedir>/TEST/lib64/python3.6/random.py", line 42, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ModuleNotFoundError: No module named 'math'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 2567, in <module>
    main()
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 793, in main
    symlink=options.symlink,
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 1088, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 935, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 1025, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 886, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command <somedir>/TEST/bin/python - setuptools pip wheel failed with error code 1

我真的尝试了很多组合(许多版本,使用 PATH 和 PYTHONPATH),但都没有运气。 任何帮助表示赞赏。

最有用的评论

venv pip 有这个并输出错误:

!"/mnt/c/Users/Artem Russakovskii/Dropbox/workspace/SNIP.test/SNIP/env-linux/bin/python3"

这是你发现的一个丑陋的错误。 从它的外观来看,似乎在某些 bash 脚本中缺少引用(考虑到这一点被忽视的频率,这不会让我感到惊讶)。

我会试着找到它,因为这种东西让我很痒。 它不会解决您的问题,但至少我们会为某人带来一些好处。

所有12条评论

嗨,未来用户的信息,以防他们在这个错误被粉碎之前需要修复。

由于我的项目是在python3 上,我回避了替换的问题:

virtualenv --always-copy

python -m venv --copies

这适用于CentOS 7.x (没有ModuleNotFoundError: No module named '_socket'ModuleNotFoundError: No module named 'math' ),并且基本上远离了 virtualenv,这在我的项目中无论如何都是一个可行的选择。

那么选项名称已更改?
IMO,(如果含义相同,至少)应支持(旧) --always-copy长选项作为(新) --copies选项的别名。 这应该不难; optparse选项没有问题,其中找到的第一个长选项字符串是默认dest字符串。

@tobiasherp ,不完全是。

这两个选项指的是不同的程序: --always-copy是一个virtualenv选项, --copies用于python -m venv

我所做的是完全放弃 virtualenv,并使用-m venv ,从 python3 开始,默认情况下无需安装任何东西即可使用,并且适用于我的情况。

我懂了

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/tmp/tmp_6oib3xo/venv/lib64/python3.7/tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "/tmp/tmp_6oib3xo/venv/lib64/python3.7/random.py", line 42, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ModuleNotFoundError: No module named 'math'

当我尝试运行tests/test_virtualenv.py::test_always_copy_option

我在 OpenSUSE 15.0 和 15.1 上看到了同样的问题。

virtualenv --always-copy temp
Using base prefix '/usr'
New python executable in /srv/www/htdocs/dev.SNIP.com/apk-downloader/temp/bin/python3
Also creating executable in /srv/www/htdocs/dev.SNIP.com/apk-downloader/temp/bin/python
Command /srv/www/htdocs/dev....der/temp/bin/python3 -m pip config list had error code 1
Installing setuptools, pip, wheel...

  Complete output from command /srv/www/htdocs/dev....der/temp/bin/python3 - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/srv/www/htdocs/dev.SNIP.com/apk-downloader/temp/lib64/python3.6/tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "/srv/www/htdocs/dev.SNIP.com/apk-downloader/temp/lib64/python3.6/random.py", line 42, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ModuleNotFoundError: No module named 'math'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 11, in <module>
    load_entry_point('virtualenv==16.7.5', 'console_scripts', 'virtualenv')()
  File "/usr/lib/python3.6/site-packages/virtualenv.py", line 870, in main
    symlink=options.symlink,
  File "/usr/lib/python3.6/site-packages/virtualenv.py", line 1173, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "/usr/lib/python3.6/site-packages/virtualenv.py", line 1019, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "/usr/lib/python3.6/site-packages/virtualenv.py", line 1110, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "/usr/lib/python3.6/site-packages/virtualenv.py", line 963, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command /srv/www/htdocs/dev....der/temp/bin/python3 - setuptools pip wheel failed with error code 1

@gaborbernat这里有什么想法吗? 没有--always-copy ,它运行正常。

我尝试了venv解决方法,发现即使使用--copies它仍然会创建符号链接。 为什么?

python3 -m venv --copies temp
SNIP<strong i="8">@pylon</strong>:/srv/www/htdocs/dev.SNIP.com/apk-downloader> l temp
total 24
drwxr-xr-x 5 SNIP users 4096 Oct 30 14:09 ./
drwxr-xr-x 7 SNIP users 4096 Oct 30 14:09 ../
drwxr-xr-x 2 SNIP users 4096 Oct 30 14:09 bin/
drwxr-xr-x 2 SNIP users 4096 Oct 30 14:09 include/
drwxr-xr-x 3 SNIP users 4096 Oct 30 14:09 lib/
lrwxrwxrwx 1 SNIP users    3 Oct 30 14:09 lib64 -> lib/
-rw-r--r-- 1 SNIP users   69 Oct 30 14:09 pyvenv.cfg

@archon810 ,这是真的: /lib64python -m venv --copies仍然是一个符号链接,但幸运的是,这是唯一剩下的:尝试在没有--copies情况下运行并查看内容/lib/pyhon3.6/site-packages :很多文件都是符号链接。

我不知道这是否足以满足您的需求。 对我来说,用例是确保用户在操作他的 virtualenv 时不会无意中弄乱其他目录中的文件权限。 在这种情况下,/lib64 是一个符号链接是可以接受的,因为它保留在 virtualenv 目录结构中。

旁注:python3 默认有可用的venv ,无论如何我完全停止使用 virtualenv。

我正在尝试在 Windows 上的 WSL 中的 Dropbox 文件夹中设置 Python env,而 Dropbox 被任何符号链接弄糊涂了。 这是我要弄清楚的最后一组符号链接,如果没有这个数学崩溃,virtualenv 几乎就在那里。

我的意思是,我可以向 venv 添加一个 rm 和 cp -R 并尝试走那条路,但如果它确实按照它所说的去做并且根本没有符号链接,那就太好了。

python3 -m venv --copies env-linux && rm env-linux/lib64 && cp -R env-linux/lib env-linux/lib64

呃,事实证明venv不好,因为它不处理带有空格的目录。

virtualenv pip 有这个并且有效:

#!/bin/sh
'''exec' "/mnt/c/Users/Artem Russakovskii/Dropbox/workspace/SNIP.test/SNIP/env-linux/bin/python3" "$0" "$@"
' '''

venv pip 有这个并输出错误:

#!"/mnt/c/Users/Artem Russakovskii/Dropbox/workspace/SNIP.test/SNIP/env-linux/bin/python3"
bash: env-linux.new/bin/pip3: "/mnt/c/Users/Artem: bad interpreter: No such file or directory

使用最新的16.7.7版本确认存在此math问题。

venv pip 有这个并输出错误:

!"/mnt/c/Users/Artem Russakovskii/Dropbox/workspace/SNIP.test/SNIP/env-linux/bin/python3"

这是你发现的一个丑陋的错误。 从它的外观来看,似乎在某些 bash 脚本中缺少引用(考虑到这一点被忽视的频率,这不会让我感到惊讶)。

我会试着找到它,因为这种东西让我很痒。 它不会解决您的问题,但至少我们会为某人带来一些好处。

https://github.com/pypa/virtualenv/pull/1500现在应该一劳永逸地解决这个问题。

此页面是否有帮助?
0 / 5 - 0 等级