Import arbitrary python source file. (Python 3.3+)

Found a solution from importlib test code. Using importlib.machinery.SourceFileLoader: >>> import importlib.machinery >>> loader = importlib.machinery.SourceFileLoader(‘a_b’, ‘/tmp/a-b.txt’) >>> mod = loader.load_module() >>> mod <module ‘a_b’ from ‘/tmp/a-b.txt’> NOTE: only works in Python 3.3+. UPDATE Loader.load_module is deprecated since Python 3.4. Use Loader.exec_module instead: >>> import types >>> import importlib.machinery >>> loader = importlib.machinery.SourceFileLoader(‘a_b’, ‘/tmp/a-b.txt’) >>> … Read more

hash function in Python 3.3 returns different results between sessions

Python uses a random hash seed to prevent attackers from tar-pitting your application by sending you keys designed to collide. See the original vulnerability disclosure. By offsetting the hash with a random seed (set once at startup) attackers can no longer predict what keys will collide. You can set a fixed seed or disable the … Read more

How to install pip for Python 3 on Mac OS X?

UPDATE: This is no longer necessary as of Python3.4. pip3 is installed as part of the general Python3 installation. I ended up posting this same question on the python mailing list, and got the following answer: # download and install setuptools curl -O https://bootstrap.pypa.io/ez_setup.py python3 ez_setup.py # download and install pip curl -O https://bootstrap.pypa.io/get-pip.py python3 … Read more

Python 3: ImportError “No Module named Setuptools”

Your setup.py file needs setuptools. Some Python packages used to use distutils for distribution, but most now use setuptools, a more complete package. Here is a question about the differences between them. To install setuptools on Debian: sudo apt-get install python3-setuptools For an older version of Python (Python 2.x): sudo apt-get install python-setuptools