Where should I put my own python module so that it can be imported

后端 未结 6 1820
心在旅途
心在旅途 2020-11-29 16:53

I have my own package in python and I am using it very often. what is the most elegant or conventional directory where i should put my package so it is going to be imported

6条回答
  •  伪装坚强ぢ
    2020-11-29 17:34

    So if your a novice like myself and your directories are not very well organized you may want to try this method.

    Open your python terminal. Import a module that you know works such as numpy in my case and do the following. Import numpy

    numpy.__file__

    which results in

    '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages/numpy/__init__.py'

    The result of numpy.__file__ is the location you should put the python file with your module (excluding the numpy/__init__.py) so for me that would be

    /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages

    To do this just go to your terminal and type

    mv "location of your module" "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages"

    Now you should be able to import your module.

提交回复
热议问题