I am new to python and i have this django project, which actually has to communicate with a python package that my colleague has built. Let's say, the structure is as follows
-Mydjangoproject
-myapp
-views.py
-models.py
-Mydjangoproject
-settings.py
-urls.py
-manage.py
-db.sqlite3
-colleagues_python_package
-package1
-script1.py
-script2.py
-package2
-info1.py
-info2.py
When I try to run my colleague's script1.py which has the following code to import,
from colleagues_python_package.package2 import info1
it throws me the error
ImportError: No Module named colleagues_python_package.package2
If run in my colleague's system, this works. Is it because this package is not set in PYTHONPATH. How do I resolve this and explanation? ( and this package has to be inside django project)
Okay I found that I have to import using [dot] 's. For example, if I want to run the script1 , I'll have to import info1 as below
from ..package2 import info1
Representation is like,
1 dots - current folder
2 dots - current folder's parent
3 dots - current folder's parent's parent
Hope I ain't confusing.
尝试从python manage.py shell
导入模块,看看是否会出现任何错误。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.