Execute a Python script post install using distutils / setuptools

The way to address these deficiences is: Get the full path to the Python interpreter executing setup.py from sys.executable. Classes inheriting from setuptools.Command (such as setuptools.command.install.install which we use here) implement the execute method, which executes a given function in a “safe way” i.e. respecting the dry-run flag. Note however that the –dry-run option is … Read more

Python setup.py: How to get find_packages() to identify packages in subdirectories

This is like using the src-layout for the “foo” and “bar” packages, but the flat layout for “baz”. It’s possible, but requires some custom configuration in the setup.py. Setuptools’ find_packages supports a “where” keyword (docs), you can use that. setup( … packages=( find_packages() + find_packages(where=”./bar-pack”) + find_packages(where=”./foo-pack”) ), … ) Since find_packages returns a plain … Read more

Import error on installed package using setup.py

You have to list all packages in setup, including subpackages: setup( name = “mytestmodule”, version = “0.0.1”, description = (“A simple module.”), packages=[‘mymodule’, ‘mymodule.subdir’], ) Or you can use setuptools‘s magic function find_packages: from setuptools import setup, find_packages setup( name = “mytestmodule”, version = “0.0.1”, description = (“A simple module.”), packages=find_packages(), ) This is mentioned … Read more

Distribute a Python package with a compiled dynamic shared library

What I ended up doing is: setup( name=”py_my_lib”, version=version, # specified elsewhere packages=[”], package_dir={”: ‘.’}, package_data={”: [‘py_my_lib.so’]}, ) This way I get to import the lib by its name, and don’t have another level of nestedness: import py_my_lib and not from py_my_lib_wrapper import py_my_lib

How do I use data in package_data from source code?

The standard pkgutil module’s get_data() function will calculate the path to your data, relative to your package, and retrieve the data for you via whatever module loader Python used to import the hermes package: import pkgutil data = pkgutil.get_data(‘hermes’, ‘templates/python.tpl’) Of course in certain cases you could just read your data using a path calculated … Read more

How to include and install local dependencies in setup.py in Python?

There is a new technique (Since version 19.1) called Direct references. Just pretend like your file is hosted on localhost. from setuptools import setup path_to_my_project = “/home/user/projects/my_package” # Do any sort of fancy resolving of the path here if you need to setup(# … other arguments install_requires=[f”my_package @ file://localhost/{path_to_my_project}#egg=my_package”] )

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)