将目录导入pycharm [英] Import directory into pycharm

查看:89
本文介绍了将目录导入pycharm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将旧项目导入 pycharm 进行调试.目录结构如下:

I am trying to import a legacy project into pycharm for debugging. The directory structure looks like:

顶级文件夹--->文件夹一

top folder ---> folder one

顶层文件夹--->文件夹二

top folder ---> folder two

问题是子文件夹中的程序使用:

The problem is that programs in the sub-folders use:

 import top 
 from top import module  

Pycharm 返回错误:No module named top"

Pycharm returns the error: "No module named top"

我该如何解决这个问题?

How can I fix this?

推荐答案

首先要确保按照 Games 所说的去做,您需要确保每个代表包的文件夹都通过放置一个 __init__.py 文件,它是一个空 python 文件,完全命名为 __init__.py ,它告诉解释器该文件夹是一个 python 包.

First thing to make sure is to do what Games said, you need to make sure each folder that is representing a package is done by putting a __init__.py file which is a empty python file named exactly __init__.py that tells the interpreter that the folder is a python package.

要寻找的第二件事是,如果 PyCharm 不知道该目录,则 pycharm 喜欢抱怨导入的代码.进入项目解释器配置并进入Paths并添加不在项目中或直接在解释器下的路径引用.

Second thing to look for is that pycharm likes to complain about imported code if PyCharm does not know about that directory. Go into the Project Interpreter Configuration and go to Paths and add the path references that are not in the project or directly under the interpreter.

要添加的另一件事是通过右键单击代表您的根的文件夹并单击将目录标记为...">源根"来设置项目代码的源根.

One other thing to add, is to set the source root of your project code by right clicking the folder that represents your root and clicking the 'Mark Directory as...' > 'Source Root'.

这篇关于将目录导入pycharm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆