简体   繁体   中英

Module not found when drag and drop Python file

I have a Python script which user's drag and drop KML files into for easy use. It takes the dropped file as sys.arg[1]. When entered into the command line as myScript.py Location.kml everything works fine. But when I drag and drop the file in an error is thrown saying no module named xlsxwriter . xlsxwriter is in the same folder as my Python script in another folder named Packages. Why does it work for the command line but not when dragged and dropped? Is there some trick I am missing?

Thanks to erkysun this issue was solved! eryksun's solution worked perfectly and I found another reason it wasn't working. This was because when I dragged and dropped the file into the python script then ran os.getcwd() no matter where the file was it returned C:\\WINDOWS\\system32 . To counteract this wherever I had os.getcwd() I changed it to os.path.abspath(os.path.dirname(__file__)) and then it worked!

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.

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