错误信息 "Failed to initialize virtualenvwrapper." (WSL Windows 10)

5

介绍

在我的Windows 10上的WSL(Wsman Shell命令行,版本0.2.1)中,我安装了pyenv并尝试使用pyenv-virtualenvwrapper。 然而,即使使用与我在Ubuntu-PC上使用的相同的.bashr.profile配置文件,我似乎也无法让它正常运行。

接下来,我将阐述我尝试过的内容。

检查pyenv

username@hd1pcms0347:~$ pyenv
pyenv 1.2.26
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   --version   Display the version of pyenv
   activate    Activate virtual environment
   commands    List all available pyenv commands
   deactivate   Deactivate virtual environment
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   local       Set or show the local application-specific Python version(s)
   prefix      Display prefix for a Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall a specific Python version
   version     Show the current Python version(s) and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   virtualenv   Create a Python virtualenv using the pyenv-virtualenv plugin
   virtualenv-delete   Uninstall a specific Python virtualenv
   virtualenv-init   Configure the shell environment for pyenv-virtualenv
   virtualenv-prefix   Display real_prefix for a Python virtualenv version
   virtualenvs   List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
   virtualenvwrapper   Setup virtualenvwrapper into current shell.
   virtualenvwrapper_lazy   Setup virtualenvwrapper_lazy into current shell.
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

尝试按照上述选项运行pyenv virtualenvwrapper

username@hd1pcms0347:~$ pyenv virtualenvwrapper

Failed to initialize virtualenvwrapper.

Perhaps pyenv-virtualenvwrapper has not been loaded into your shell properly.
Please restart current shell and try again.

username@hd1pcms0347:~$ virtualenvwrapper
virtualenvwrapper: command not found
username@hd1pcms0347:~$ which virtualenvwrapper
username@hd1pcms0347:~$

通过pip安装virtualenvwrapper
username@hd1pcms0347:~$ pip install virtualenvwrapper
Collecting virtualenvwrapper
  Using cached virtualenvwrapper-4.8.4-py2.py3-none-any.whl
Collecting stevedore
  Using cached stevedore-3.3.0-py3-none-any.whl (49 kB)
Collecting virtualenv
  Using cached virtualenv-20.4.7-py2.py3-none-any.whl (7.2 MB)
Collecting virtualenv-clone
  Using cached virtualenv_clone-0.5.4-py2.py3-none-any.whl (6.6 kB)
Collecting pbr!=2.1.0,>=2.0.0
  Using cached pbr-5.6.0-py2.py3-none-any.whl (111 kB)
Collecting six<2,>=1.9.0
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting appdirs<2,>=1.4.3
  Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting distlib<1,>=0.3.1
  Using cached distlib-0.3.2-py2.py3-none-any.whl (338 kB)
Collecting filelock<4,>=3.0.0
  Using cached filelock-3.0.12-py3-none-any.whl (7.6 kB)
Installing collected packages: six, pbr, filelock, distlib, appdirs, virtualenv-clone, virtualenv, stevedore, virtualenvwrapper
Successfully installed appdirs-1.4.4 distlib-0.3.2 filelock-3.0.12 pbr-5.6.0 six-1.16.0 stevedore-3.3.0 virtualenv-20.4.7 virtualenv-clone-0.5.4 virtualenvwrapper-4.8.4

再次检查是否有效

username@hd1pcms0347:~$ virtualenvwrapper
virtualenvwrapper: command not found
username@hd1pcms0347:~$ pyenv virtualenvwrappr
pyenv: no such command `virtualenvwrappr'
username@hd1pcms0347:~$ pyenv virtualenvwrapper

Failed to initialize virtualenvwrapper.

Perhaps pyenv-virtualenvwrapper has not been loaded into your shell properly.
Please restart current shell and try again.

username@hd1pcms0347:~$ pyenv-virtualenvwrapper

Failed to initialize virtualenvwrapper.

Perhaps pyenv-virtualenvwrapper has not been loaded into your shell properly.
Please restart current shell and try again.

username@hd1pcms0347:~$ pyenv global
3.9.4
username@hd1pcms0347:~$ pyenv local
pyenv: no local version configured for this directory

请按照步骤重新从github页面安装pyenv-virtualenvwrapper

username@hd1pcms0347:~$ $ git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $(pyenv root)/plugins/pyenv-virtualenvwrapper
$: command not found
username@hd1pcms0347:~$ git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $(pyenv root)/plugins/pyenv
-virtualenvwrapper
fatal: destination path '/home/username/.pyenv/plugins/pyenv-virtualenvwrapper' already exists and is not an empty directory.
username@hd1pcms0347:~$ export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
username@hd1pcms0347:~$ pyenv virtualenvwrapper

Failed to initialize virtualenvwrapper.

Perhaps pyenv-virtualenvwrapper has not been loaded into your shell properly.
Please restart current shell and try again.

username@hd1pcms0347:~$ virtualenvwrapper
virtualenvwrapper: command not found

检查可执行文件的位置

username@hd1pcms0347:~$ ls -R /home/username/.pyenv/plugins/pyenv-virtualenvwrapper
/home/username/.pyenv/plugins/pyenv-virtualenvwrapper:
LICENSE  README.md  bin  install.sh  shims  test

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/bin:
pyenv-sh-virtualenvwrapper  pyenv-sh-virtualenvwrapper_lazy  pyenv-virtualenvwrapper  pyenv-virtualenvwrapper_lazy

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/shims:
deactivate

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test:
command.bats    pyvenv.bats  stubs             tmp         version.bats       virtualenvwrapper.bats
installer.bats  setup.bats   test_helper.bash  unset.bats  virtualenvwrapper  virtualenvwrapper_lazy.bats

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/stubs:
stub

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/tmp:

/home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/virtualenvwrapper:
virtualenvwrapper.sh  virtualenvwrapper_lazy.sh

尝试执行感兴趣的脚本“virtualenvwrapper.sh”。
username@hd1pcms0347:~$ ./home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/virtualenvwrapper/virtualenvwrapper.sh
-bash: ./home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/virtualenvwrapper/virtualenvwrapper.sh: No such file or directory
username@hd1pcms0347:~$ bash /home/username/.pyenv/plugins/pyenv-virtualenvwrapper/test/virtualenvwrapper/vi
rtualenvwrapper.sh
virtualenvwrapper.sh is loaded
username@hd1pcms0347:~$ virtualenvwrapper
virtualenvwrapper: command not found
username@hd1pcms0347:~$ pyenv virtualenvwrapper

Failed to initialize virtualenvwrapper.

Perhaps pyenv-virtualenvwrapper has not been loaded into your shell properly.
Please restart current shell and try again.

我不知道还有什么其他方法可以让它工作。坦白地说,在其他Ubuntu/Linux发行版上,使用pyenvvirtualenvwrapper应用程序时会出现各种问题,这也是令人惊讶的。通常情况下,当它们工作时,它们非常棒,但更多时候安装它们是一件非常麻烦的事情。
1个回答

5

在我的Mac上(BigSur 11.5.1上的Bash shell),我在尝试设置virtualenvwrapper时遇到了同样的错误。最终,我解决了这个问题:在安装了pyenv和virtualenvwrapper之后,您的~/.bashrc应该如下所示:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
export WORKON_HOME=$HOME/.virtualenvs

eval "$(pyenv init -)"
pyenv virtualenvwrapper_lazy

然后执行source ~/.bashrc命令(同时确保您的.bash_profile或.profile文件中已经载入.bashrc)。

1
非常感谢,看起来这个工作完美无瑕!(Windows 10,WSL(Wsman Shell命令行),版本0.2.1) - Andreas L.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接