I am trying to import pyroscope module which is residing in my ~/lib/pyroscope
directory. The example here shows that the script use from pyrocore.scripts import base
. I don't see any tricks based on imp.load_source
. So I am kinda puzzled - what kind of environment I have to build in order to import this module( without relocating the library )?
You have to make sure that ~/lib
is in the path python uses to look for libraries. One way to do this is set the PYTHONPATH
environment variable in a shell:
export PYTHONPATH=~/lib
Alternatively, you can change the path in your script before the import
:
import os
import sys
sys.path.insert(0, os.path.expanduser('~/lib'))
For more information, please have a look at The Module Search Path in the documentation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.