Hello im newbie on python. i want ask my problem. how about if i in module2.py and i put code from projects.package2.module3 import function and execute module2.py there is a error, cannot find module "projects" if i use relative path like from ...package2.module3 import function there is error cannot find parent relative path bla bla. why? Can u explain this? Thx.
@@Thelaunius Having the same issue here. This is EXACTLY why Python is a "toy" programming environment. Literally you can only either: (a) upload your python files to pypi to be used by others, or (b) keep python files that you want to "import" in the same directory (or a subdirectory ) as your working program. Literally, all data science and all that is done in this "sandbox" created by Python. This is why the language can't be taken seriously.
@@atlantic_love Hi, In case this is still helpful to you guys or to anybody else who is going to read this in future, I wish to clarify that, as far as my understanding goes, relative imports mostly and even sometimes absolute imports in Python will almost always result in an error if we try to run a particular file having import statement directly from the command prompt( same scenario in most IDE's too). If we are developing some sort of application and we organize our files into different folders/packages correctly as is illustrated in this video, then we would of course have a file at the top level that starts our application. Only that file can and should be run directly from command prompt. For all other non library/application projects that you do in python, simply put all the module files in the same folder and call them as per requirement in any file using direct import statements. So during the development of your library/app you can follow this approach in order to ensure that each module is working properly and once all work including the top level file that starts the app is done, you can then proceed to organize them into folders/packages and add the required absolute/relative import statements. Then simply test out your whole app. Relative imports still remains an area of python where a google search would only leave someone in even more darkness.
Hey thanks for vedio , but I tried like this but got package 2 not found import error , how to deal it , I am handling this by adding the path of folders package 2 and other to environment variable PYTHONPATH
You are probably using python2 where you need an __init__.py file in your package folder to make it known to the interpreter as importable resource. You can make sure which version you are using with `import sys` and `print(sys.version)`