Virtualenv始终由python 2而不是python 3构建

时间:2019-01-17 21:43:50

标签: python-3.x python-2.7 pip virtualenv

在尝试为python创建虚拟环境时,我始终收到以下错误。在我看来,virtualenv / pip默认使用python 2,而不是在构建环境时使用。 不是不是说该环境是 构建的python2,而是是由 构建的python2。我认为这是问题所在,我们将提供任何帮助。

[brad@reason Attack_Analysis]$ virtualenv -p /usr/local/bin/python3.7 venv
Running virtualenv with interpreter /usr/local/bin/python3.7
Using base prefix '/usr/local'
New python executable in /home/brad/Development/Attack_Analysis/venv/bin/python3.7
Also creating executable in /home/brad/Development/Attack_Analysis/venv/bin/python
Installing setuptools, pip, wheel...

  Complete output from command /home/brad/Developme...s/venv/bin/python3.7 - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 18, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py", line 38, in <module>
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/usr/local/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
ImportError: cannot import name 'main' from 'pip' (/home/brad/.local/lib/python2.7/site-packages/virtualenv_support/pip-18.1-py2.py3-none-any.whl/pip/__init__.py)
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv.py", line 2438, in <module>
    main()
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv.py", line 768, in main
    symlink=options.symlink,
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv.py", line 1030, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv.py", line 983, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "/home/brad/.local/lib/python2.7/site-packages/virtualenv.py", line 861, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command /home/brad/Developme...s/venv/bin/python3.7 - setuptools pip wheel failed with error code 1

我的vitualenv是最新的

[brad@reason Attack_Analysis]$ virtualenv --version
16.2.0

我的点子已更新,但似乎适用于python 2,而不是3。我如何使其适用于python 3?我通过make install进行安装,就像在Redhat 7.5上一样。

[brad@reason Attack_Analysis]$ pip --version
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

使用pip3时,似乎没有root却没有root,因此我的pip3已经过时了。当我需要root来执行此操作并遇到此问题时,不确定如何更新它。

[brad@reason ~]$ pip3 --version
pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)
[brad@reason ~]$ sudo pip3 install --upgrade pip
[sudo] password for brad: 
sudo: pip3: command not found

我的PYTHONPATH为空。应该是吗我想我以前没有改变过这个,不确定这是否是一个问题。

[brad@reason ~]$ echo $PYTHONPATH

[brad@reason ~]$

1 个答案:

答案 0 :(得分:0)

这是我解决此问题的方法(在Linux上):

apt install python3-pip
pip3 install virtualenv