Quantcast
Channel: Ryan Varley » Ryan Varley
Viewing all articles
Browse latest Browse all 8

How to add folders to your python path on Mac OS

$
0
0

So you have a few custom packages you want to store in dropbox or elsewhere on your mac but can’t figure out how to add files permanently to your python path? Heres how.

Adding files to your python path has many pitfalls and it took me a while to figure out but heres the basic issues i ran into for quick reference

  • how the hell do i add something to the python path
  • not having permission to view/add files to a current python path directory
  • .pth file not being recognised (can’t be formatted with UTF 8 with Dom, use UTF 8)

How to add a folder to your python path

  1. start python from the command line by typing python. then enter
    import sys
    sys.path
    
  2. The output gives a list of folders in the current python path. Look for one ending with ‘site-packages’ and note it down
  3. quit python ( ‘quit()’) and enter the following in the terminal where <path> is the path you just copied
    import sys
    sys.path
    
  4. Now open a text editor like sublime and add the path to the folder you want to add to your path ie i added
    import sys
    sys.path
    

    and save with UTF8/ASCII (in sublime file->save with encoding -> UTF8) and save it anywhere easy (your about to copy it)
  5. Now go back to your open terminal and type
    import sys
    sys.path
    
  6. You’re done! open python again and follow step 1 and see if your new path is there. If it is add your packages to this folder and try importing them.

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images