简体   繁体   English

在 pycharm 中更改终端的 virtualenv

[英]Changing the virtualenv for the terminal in pycharm

I was postponing this question since i am not sure this is the right place to ask it.我推迟了这个问题,因为我不确定这是问它的正确地方。 But i don't find a clear answer either.但我也没有找到明确的答案。

I am running pycharm 2018.1.4, on windows and it seems that i can't change the virtual env that running in the terminal in pycharm.我在 Windows 上运行 pycharm 2018.1.4,似乎我无法更改在 pycharm 终端中运行的虚拟环境。 When i check the python version in the terminal i get version 2.7.3, for the project interpreter i have python 3.6 and for my run configurations i have the same 3.6 interpreter.当我在终端中检查 python 版本时,我得到版本 2.7.3,对于项目解释器,我有 python 3.6,对于我的运行配置,我有相同的 3.6 解释器。 There are no problems running the development server or anything like that, just in the terminal i can't run the manage.py script without getting following.运行开发服务器或类似的东西没有问题,只是在终端中,我无法在没有关注的情况下运行 manage.py 脚本。

ImportError: Couldn't import Django.导入错误:无法导入 Django。 Are you sure it's installed and available on your PYTHONPATH environment variable?您确定它已安装并在您的 PYTHONPATH 环境变量中可用吗? Did you forget to activate a virtual environment?您是否忘记激活虚拟环境?

I understand the error, i just dont get why it is using that virtuals env instead of the one configured as project interpreter.我理解错误,我只是不明白为什么它使用那个 virtuals env 而不是配置为项目解释器的那个。 Anyone else stumbled upon this problem?其他人偶然发现了这个问题?

As far as i know, Pycharm's terminal is not bound to Project Interpreter and the IDE related features.据我所知,Pycharm 的终端并没有绑定到 Project Interpreter 和 IDE 相关功能。 To make it work, you'll have to manually activate your virtualenv in the terminal.要使其工作,您必须在终端中手动激活您的 virtualenv。

It can be due to various reasons, You can try the following command once the virtualenv is activated这可能是由于各种原因,您可以在激活 virtualenv 后尝试以下命令

python --version

If it shows python 2.7 as the version then it means in your system you have given python command to respond to the 2.7 version.如果它显示 python 2.7 作为版本,那么这意味着在你的系统中你已经给出了 python 命令来响应 2.7 版本。 Its more like a name tag.它更像是一个名称标签。

Try python3 --version and it should give you back "Python 3.6".试试python3 --version ,它应该会给你“Python 3.6”。

If that's the case, then use python3 manage.py runserver and it should work perfectly如果是这种情况,那么使用python3 manage.py runserver它应该可以完美运行

  1. In Pycharm go to project setting,then go to project interpreter make sure that you have your required python virtual environment (which I think you did it already)在 Pycharm 中转到项目设置,然后转到项目解释器确保您拥有所需的 Python 虚拟环境(我认为您已经做到了)
  2. Under same selected environment, make sure that you have installed Django在相同的选择环境下,确保你已经安装了 Django
  3. Of course, if there is the dependency on Django, you can just type当然,如果有对Django的依赖,直接输入即可

    pip install django

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

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