简体   繁体   English

Pycharm-Python中的导入模块-不同的行为-MAC与Windows

[英]Pycharm - Import Module in Python - Different behaviour - MAC vs Windows

My folder structure: 我的文件夹结构:

  • /backend/webservices.py /backend/webservices.py
  • /backend/csv_utilities.py /backend/csv_utilities.py

webservices.py starts like this: webservices.py开始是这样的:

from flask import Flask, request
from werkzeug.utils import secure_filename
from backend.csv_utilities import *
import os
  • If I run webservices.py on MAC, I won't have any problems. 如果我在MAC上运行webservices.py ,则不会有任何问题。
  • If I run webservices.py on Windows, I will get a module not found error. 如果我在Windows上运行webservices.py ,则会收到模块未找到错误。

Changing webservices.py like this: 像这样更改webservices.py

from flask import Flask, request
from werkzeug.utils import secure_filename
from csv_utilities import *
import os

works on both ; 两者都工作 ; MAC and Windows. MAC和Windows。 But in PyCharm (on MAC, I didn't try on Windows) now I get an error marked on csv_utilities and it says: unresolved reference 'csv_utilities'. 但是在PyCharm中(在MAC上,我没有在Windows上尝试过),现在我得到了一个在csv_utilities标记的错误,它说:未解析的引用'csv_utilities'。

Why is this error there? 为什么会出现此错误? I can run it without problems. 我可以毫无问题地运行它。 Is it a Pycharm issue or am I doing something not in the right way? 是Pycharm问题,还是我做事不正确?

I had a similar issue once. 我曾经有过类似的问题。 Try Mark directory as Sources Root option on your backend folder. 尝试在后端文件夹上将目录标记为Sources Root选项。 It worked for me. 它为我工作。

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

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