내 폴더/파일 structrue은 다음과 같습니다가져 오기 다른 파일 오류
testpkg/test/__init__.py;
testpkg/test/test1.py
testpkg/test/test2.py
testpkg/setup.py
testpkg/test/__init__.py
파일이 비어 있습니다.
testpkg/test/test1.py
파일 내용 :
class Test1:
def __init__(self, name):
self.name = name
def what_is_your_name(self):
print(f'My name is {self.name}')
testpkg/test/test2.py
파일 내용 :
from .test1 import Test1
def main():
t = Test1('me')
t.what_is_your_name()
if __name__ == '__main__':
main()
/testpkg/setup.py
내용 :
from setuptools import setup
setup(name='test',
version='0.1',
packages=['test'],
entry_points={
'console_scripts': [
'test_exec = test.test2:main'
]
}
)
내가 할 수없는 디버그/test2.py
스크립트를 직접 실행 그것은 나에게 오류를 제공하기 때문에 :
pip install -U .
로를 설치할 때
» python test/test2.py
Traceback (most recent call last):
File "test/test2.py", line 1, in <module>
from .test1 import Test1
ModuleNotFoundError: No module named '__main__.test1'; '__main__' is not a package
는하지만 그것은 작동합니다
이» pip install -U .
Processing /home/kossak/Kossak/files_common/PythonProjects/testpkg
Installing collected packages: test
Found existing installation: test 0.1
Uninstalling test-0.1:
Successfully uninstalled test-0.1
Running setup.py install for test ... done
Successfully installed test-0.1
» test_exec
My name is me
질문은 : 그것은 두 가지 방법으로 작동하므로 어떻게 제대로 test2.py
를 작성 - 직접 (그래서 그것을 디버깅 할 수 있습니다 PyCharm을 사용하거나 python test2.py
으로 실행) test
패키지를 설치 한 후? 나는 줄 변경 시도 :
from .test1 import Test1
from test1 import Test1
(제거 점)
에 내가 명령 줄에서test2.py
를 실행할 수 있습니다,하지만 설치 한 후, 내 스크립트 "test_exec는"제공 오류 :
Traceback (most recent call last):
File "/home/kossak/anaconda3/bin/test_exec", line 11, in <module>
load_entry_point('test==0.1', 'console_scripts', 'test_exec')()
File "/home/kossak/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 565, in load_entry_point
File "/home/kossak/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2598, in load_entry_point
File "/home/kossak/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2258, in load
File "/home/kossak/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2264, in resolve
File "/home/kossak/anaconda3/lib/python3.6/site-packages/test/test2.py", line 1, in <module>
from test1 import Test1
ModuleNotFoundError: No module named 'test1'
인해 상대적으로 수입에 당신이'파이썬 -m test.test2' 모듈로 실행해야합니다 –