我遵循打包Python项目教程,一切都很好。我上传了我的软件包到pypi,我可以安装它。然而,在进口时,发生了一些奇怪的事情;
在外壳里面,它工作得很好。
>>> import noodle_extensions
>>> # no errors indicate that it was imported properly.
>>> print(noodle_extensions)
<module 'noodle_extensions' from 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\noodle_extensions\\__init__.py'>
然而,在VScode内部,我得到了这个;
import noodle_extensions
Traceback (most recent call last):
File "c:/Users/user/OneDrive/Desktop/Codes/Python/Tests/test.py", line 1, in <module>
import noodle_extensions
ModuleNotFoundError: No module named 'noodle_extensions'
control+clicking它不工作。皮林特认为它不存在。
就pip install
位置的文件而言,我有包含__init__.py
、.egg-info
文件夹和.dist-info
文件夹的noodle_extensions
。
有什么我能做的吗?
发布于 2020-11-25 00:45:00
根据您的描述,"noodle_extensions
“模块存在于环境"Python3.9
”中,请单击VSCode左下角显示的Python解释器(或使用F1
,python: Select Interpreter
),然后选择"Python3.9
":
或者在当前选择的"noodle_extensions
“环境中重新安装模块"Python3.8
”。
检查安装包:
参考资料:VSCode中的环境.
发布于 2020-11-24 18:54:11
终端上的PYTHONPATH似乎与VSCode不匹配。确保在VSCode中选择右python解释器(左下角)。
要在从终端运行时检查解释器,请使用以下命令:
# Linux:
$ which python
# Windows:
> where python
# or
> where py
如果您使用python虚拟环境,请确保您的包在环境中安装/可用,并且环境配置为VSCode launch.json
。
发布于 2021-01-03 00:27:12
在VSCODE设置中,我也遇到了同样的问题。我的解决方案听起来可能非常愚蠢,但我所要做的就是关闭并重新启动VSCODE,并开始显示导入。
https://stackoverflow.com/questions/64997719
复制相似问题