PyFAQ

Import module from parent directory

origin

  • Solution with sys.path hacks

1
2
3
import sys
sys.path.append("the/path/your/module/stored/in")
import your_module
  • Solution without sys.path hacks

1 ) Add a setup.py to the root folder

The contents of the setup.py can be simply

1
2
3
from setuptools import setup, find_packages

setup(name='myproject', version='1.0', packages=find_packages())

Basically “any” setup.py would work. This is just a minimal working example.

2 )

Removing the package is also possible with pip uninstall package-name, and package name can be read from pip list


Pillow(PIL) xor two image get ValueError: image has wrong mode

from pillow documentation see more

Logical XOR between two images.

Both of the images must have mode “1”.

if you want to get two RGB picture xored, use numpy or other codes mannually.


Python module do not have the attributes expected

1
AttributeError: partially initialized module 'csv' has no attribute 'DictWriter' (most likely due to a circular import)

Don’t name your file csv.py.
When you do so, Python will look in your file for the csv code instead of the standard library csv module.