I am trying to pip package C library (https://github.com/lh3/bwa). It seems I am able to build the package, however, it cannot find the C library when I try to call it from the package itself. Although, locally I am able to install and call this C library.
I expect the package that I called bwaPython to get installed and the C library (bwa) to get called through one of package`s methods.
Here is what I am running from the root project folder, where my setup.py is:
sultan@Sultans-MacBook-Pro bwaPython % python3 -m pip install .
Processing /Users/sultan/bwaPython
Preparing metadata (setup.py) ... done
Building wheels for collected packages: bwaPython
Building wheel for bwaPython (setup.py) ... done
Created wheel for bwaPython: filename=bwaPython-0.0.0-py3-none-any.whl size=1758 sha256=5eecae6b41154ec7c4463c578b526cc22473c0cd971aab8505f6526b37b1a350
Stored in directory: /private/var/folders/q2/p3rkrrv9311c6pk2q4s7psxr0000gn/T/pip-ephem-wheel-cache-a7mlaws3/wheels/07/a6/db/ba14333ebca4820ddd16ca2c0be0a4b82fe15bbab3ab428607
Successfully built bwaPython
Installing collected packages: bwaPython
Attempting uninstall: bwaPython
Found existing installation: bwaPython 0.0.0
Uninstalling bwaPython-0.0.0:
Successfully uninstalled bwaPython-0.0.0
Successfully installed bwaPython-0.0.0
It seems to get built. However, when I try to call one of its methods, it returns the following error:
Python 3.10.6 (v3.10.6:9c7b4bd164, Aug 1 2022, 17:13:48) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bwaPython
>>> bwaPython.generate_bwa()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/bwaPython/subprocesses.py", line 5, in generate_bwa
subprocess.call(["bwa", "index"])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 345, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1845, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bwa'
>>>
The source folder in the project root folder is named bwaPython. It has two scripts, __init__.py and subprocesses.py
subprocesses.py contains the following function that I am trying to call.
def generate_bwa():
subprocess.call(["bwa", "index"])
This is setup.py
I call it through python3 -m pip install .
import os
from setuptools import setup
from setuptools.command.install import install
import subprocess
import sys
from setuptools import find_packages, Extension
def compile_and_install_software():
"""Used the subprocess module to compile/install the C software."""
cmd = "git clone https://github.com/lh3/bwa.git"
subprocess.check_call(cmd, shell=True)
cmd = "cd bwa; make"
subprocess.check_call(cmd, shell=True)
cmd = "echo 'export PATH=$PATH:~/bwaPython/bwa' >> ~/.zshrc"
subprocess.check_call(cmd, shell=True)
cmd = "echo 'export PATH=$PATH:~/bwaPython/bwa' >> ~/.bashrc"
subprocess.check_call(cmd, shell=True)
cmd = "echo 'export PATH=$PATH:~/bwaPython/bwa' >> ~/.bash_profile"
subprocess.check_call(cmd, shell=True)
cmd = "export PATH=$PATH:~/bwaPython/bwa"
subprocess.check_call(cmd, shell=True)
cmd = "source ~/.zshrc"
subprocess.check_call(cmd, shell=True)
cmd = "source ~/.bashrc"
subprocess.check_call(cmd, shell=True)
cmd = "source ~/.bash_profile"
subprocess.check_call(cmd, shell=True)
class CustomInstall(install):
"""Custom handler for the 'install' command."""
def run(self):
compile_and_install_software()
super().run()
setup(
name="bwaPython",
cmdclass={"install": CustomInstall},
packages=find_packages(),
)
To re-iterate, locally I am able to install C library (bwa), however, running the same commands through setup.py and calling the the library from bwaPython package I have created, it cannot find this "bwa" library.
Any help appreciated. Thank you!