Where python modules on

When the python program uses import XXX, python parser in the current directory, and third-party modules have been installed in search xxx, if not all search will throw an error.
Use sys.path.append () method may temporarily add search paths, to facilitate more simple import other packages and modules. This method of introduction path will expire in python program exits.
Copyright: CSDN reference content from bloggers "- Makino -" article

Reproduced please indicate the source https://www.cnblogs.com/sogeisetsu/p/11415657.html

Assuming that the module file name filename.py

  • The first step in the console input
import os
os.path.abspath('.\\filename.py')   #获得你要导入的模块的路径
'C:\\Users\\14469\\Desktop\\untitled\\filename.py'  
  • The second step, just copy the path, and then added to sys.path
import sys
sys.path.append('C:\\Users\\14469\\Desktop\\untitled\\filename.py'  )

In this way it is guided into the module, but this is only temporary import module can only be effective in the current folder, the python's library path not find it , it is also very suitable for beginners

Guess you like

Origin www.cnblogs.com/sogeisetsu/p/11415657.html