Where shall I put my self-written Python packages? -


is there canonical location put self-written packages? own search yielded blog post where put version-independent pure python packages , so question canonical location under linux, while working on windows.

my use case able import own packages during ipython session site-package, no matter in working directory started session. in matlab, corresponding folder example c:/users/ojdo/documents/matlab.

import mypackage mp mp.awesomefunction() ... 

thanks two additional links, found not intended answer question, solution more , - ironically - explained in first search result, obfuscated version-(in)dependent site-package lingo.

answer original question

i wanted know if there canonical (as in "default") location self-written packages. , exists:

>>> import site >>> site.user_site 'c:\\users\\ojdo\\appdata\\roaming\\python\\python27\\site-packages' 

the docs on user scheme package installation state folder - if exists - automatically added sys.path.

custom directory own packages

  1. create directory anywhere, e.g. c:\users\ojdo\documents\python\libs.
  2. add file sitecustomize.py site-packages folder of python installation, i.e. in c:\python27\lib\site-packages (for users) or site.user_site (for single user).
  3. this file filled following code:

    import site site.addsitedir(r'c:\users\ojdo\any\folder\you\like\libs') 
  4. voilĂ , new directory automatically added sys.path in every (i)python session.

how works: package site, automatically imported during every start of python, tries import package sitecustomize custom package path modifications. in case, dummy package consists of script adds personal package folder python path.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -