我在pycharm中的文件夹结构如下。
--python
--concepts
--common
--myds.py
--__init__.py
--data_structures
--test_ds.py
我在test_ds.py
from common import my_ds
我收到以下错误。
ImportError: No module named 'common'
我已将common
添加到Settings --> Project Interpreter -> Interpreter Paths
并且文件夹显示为library root
。
为什么我会收到此错误。
答案 0 :(得分:1)
试试Sub MoveContactInfo()
Dim Search As String
Dim f As Range
Dim Data() As Variant
Dim x As Long
Dim wb As Workbook, ws As Worksheet
Search = "CWS"
ReDim Data(5, x)
With Sheets("Master Data Set")
For Each f In .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
If f.Value = Search Then
ReDim Preserve Data(6, x)
Data(0, x) = f(1, "E")
Data(1, x) = f(1, "F")
Data(2, x) = f(1, "G")
Data(3, x) = f(1, "H")
Data(4, x) = f(1, "I")
Data(5, x) = f(1, "J")
x = x + 1
End If
Next
If Not f Is Nothing Then
Set wb = Workbooks.Open(Filename:="D:\My Documents\Excel Spreadsheets\TEST.xls")
If Not wb Is Nothing Then
On Error Resume Next
Set ws = wb.Worksheets(Search)
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Worksheet not found-> " & Search, vbInformation, "Retry"
Else
ws.Cells(4, 1).Resize(UBound(Data, 2), UBound(Data, 1)) = Application.Transpose(Data)
End If
End If
End If
End With
End Sub
。还要确保该目录中有from ..common import my_ds
个文件(不是必需的,但这是一个好习惯)。
至于__init__.py
,它们表示您正在从父包导入到您当前所在的那个。
答案 1 :(得分:0)
你需要将你的公共文件夹放到python包中,以便在python中导入它。我认为您已尝试在init
文件夹中创建common
文件但实际上必须是__init__.py
。像这样重命名然后你的包将对python可见。
希望它有所帮助!