简体   繁体   English

IntelliJ idea 解析 python venv 依赖

[英]IntelliJ idea resolving python venv depenency

In my project I have在我的项目中我有

import datetime as dt

Which can not be resolved in IntelliJ idea..在 IntelliJ idea 中无法解决..

I do have requirements.in file我有 requirements.in 文件

python -m piptools compile --upgrade sergii-requirements.in python -m piptools 编译 --upgrade sergii-requirements.in

and generated requirements.txt with datetime defined there并生成 requirements.txt,其中定义了日期时间

python -m piptools sync requirements.txt python -m piptools 同步要求.txt

These dependencies are set in my activated virtual environment ( venv folder)这些依赖项在我激活的虚拟环境中设置( venv文件夹)

yet, I am not sure how to make IntelliJ idea aware of that venv.但是,我不确定如何让 IntelliJ idea 知道该 venv。 and my dependencies and make it resolved?和我的依赖关系并解决它? (not that intuitive.. for java dev..) (不是那么直观..对于 java dev..)

UPDATE : I did try it in PyCharm , it did work as soon as I set:更新:我确实在PyCharm中尝试过,它在我设置后立即起作用:

Project SKD to /home/user/projects/my-project/venv/bin/python3.9 - it did resolve everything.将 SKD 项目添加到/home/user/projects/my-project/venv/bin/python3.9 - 它确实解决了所有问题。

Same thing did not & have not yet worked in IntellJ Idea.. (2021.1)同样的事情在 IntellJ Idea 中没有而且还没有工作.. (2021.1)

Update 2:更新 2:

BUT: how do I know that resolved depenency is from my venv.但是:我怎么知道已解决的依赖性来自我的 venv. Seems it is not.似乎不是。

Ok.行。 The reason is.原因是。 My python plugin had an issue.我的 python 插件有问题。 I had to upgrade it to the latest intelli idea version, to be compatible.我必须将它升级到最新的智能理念版本,才能兼容。

Hope it will save someone's time once googled for this issue.希望一旦用谷歌搜索这个问题,它会节省某人的时间。

-- --

yet.. is not nessesary the answer.然而.. 不是必要的答案。 how do I know that choosing the python SDK in my env actually uses my venv dependencies - from venv and not.我怎么知道在我的环境中选择 python SDK 实际上使用了我的 venv 依赖项 - 来自 venv 而不是。

I did remove all from venv.我确实从 venv 中删除了所有内容。 And Idea still resolves datetime .而 Idea 仍然解析datetime (it is getting from global dependencies) (它来自全局依赖项)

So please do not consider it as final answer .. not yet.所以请不要将其视为最终答案.. 还没有。

It did work out though If I remove all other global deps and re-setup my venv env.如果我删除所有其他全局 deps 并重新设置我的 venv env,它确实有效。

Seems, IntellyJ Idea is too intelegent - resolving with everything it could find - from venv and not.似乎,IntellyJ Idea 太聪明了——用它能找到的一切来解决——来自 venv 而不是。

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

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