简体   繁体   English

Pyenv virtualenv没有激活,尝试了我所知道的一切

[英]Pyenv virtualenv not activating, tried everything I know

if someone could help me out with this issue it would be wonderful. 如果有人可以帮助我解决这个问题,那就太好了。 I've currently tried everything over the last few days to get it to work with no success. 目前,我已经尝试了过去几天的所有方法,以使其无法正常工作。 I have used pyenv and the plugin virtualenv for about a month now with no issues. 我已经使用pyenv和插件virtualenv大约一个月了,没有任何问题。 One day I woke up and found that I was unable to activate my virtualenv created by pyenv. 有一天,我醒来后发现无法激活pyenv创建的virtualenv。 Source bin/activate stopped working. 源bin / activate停止工作。 I did everything from reinstalling pyenv all the way to reinstalling Kubuntu and trying again with no success. 从重新安装pyenv到重新安装Kubuntu并重试均未成功,我做了一切。 I can't tell whats wrong. 我不知道怎么了。 I get no errors as you can see from the image below. 从下图可以看到,我没有任何错误。 To my understanding every time I activated a virtualenv it would show in my console before my name which it isn't doing anymore. 据我了解,每次我激活virtualenv时,它都会在控制台中以我的名字显示,而不再显示该名称。 I made sure to add "echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc" and all the other things required. 我确保添加“ echo'eval“ $(pyenv virtualenv-init-)”'>>〜/ .bashrc”以及所有其他需要的东西。 All the other options available with pyenv still work fine, its only the activating of my virtualenv. pyenv可用的所有其他选项仍然可以正常工作,这仅是激活我的virtualenv。 Please help. 请帮忙。 Thanks 谢谢

“激活”后的外观图片

This took me a bit to understand too, especially because I managed my virtualenv's with virtualenvwrapper before. 这也让我有些了解,特别是因为我之前使用virtualenvwrapper管理我的virtualenv。 What helped is that I looked through the function and saw this: 有用的是,我浏览了该函数并看到了以下内容:

  if [[ "$(pyenv version-name)" == "system" ]]; then
    pyenv deactivate || true
  elif [[ "$VIRTUAL_ENV" != "$(pyenv prefix)" ]]; then
    pyenv deactivate || true
    pyenv activate 2>/dev/null || true
  fi

What isn't covered is that when you create a virtualenv in pyenv, it shows up as a version. 没有涵盖的是,当您在pyenv中创建virtualenv时,它会显示为一个版本。 So when you do 所以当你这样做

pyenv versions

You get a list of your pythons -with- your virtual environments. 您将获得虚拟环境中的python列表。 To get this to work, its a combination of old functionality and new. 为了使其正常工作,它结合了旧功能和新功能。 You can do: 你可以做:

user@server [00:00:00] [~]
-> % cd Development/test
user@server [00:00:00] [~/Development/test]
-> % pyenv shell test
(test)user@server [00:00:00] [~/Development/test]
-> %

Or for automagic: 或自动:

user@server [00:00:00] [~]
-> % cd Development/test
user@server [00:00:00] [~/Development/test]
-> % pyenv local test
(test)user@server [00:00:00] [~/Development/test]
-> %

This drops a .python-version file with the python version, which pyenv reads and uses as the virtualenv python. 这会删除带有python版本的.python-version文件,pyenv会将其读取并用作virtualenv python。

Just remember to manage your virtualenv like python versions of pyenv and you should be able to keep things straight. 只要记住要像pyenv的python版本一样管理您的virtualenv,就应该可以保持顺畅。 For instance, to then deactivate automagically you just change directories. 例如,要自动禁用,只需更改目录。 If you did pyenv shell, you will need to pyenv shell --unset or pyenv shell {another_version} to move virtualenv. 如果您使用pyenv shell,则需要pyenv shell --unset或pyenv shell {another_version}才能移动virtualenv。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM