Search code examples
pythonmodulepython-module

Using a folder for personal modules in Python


I have created a folder named C:\Python27\Lib\site-packages\perso and inside I have put a file mymodule.py. The goal is to have this module accessible from any future Python script.

Let's do a D:\My Documents\test.py file:

import mymodule   #fails
import perso.mymodule   #fails

Why does it fail? How to import a module from C:\Python27\Lib\site-packages\perso? What are the best practice for using user-modules in all Python scripts of the same computer?


Solution

    1. check PythonPath
    2. create __init__.py to use perso as package