toruseo / UXsim

Vehicular traffic flow simulator in road network, written in pure Python
https://toruseo.jp/UXsim/docs/
MIT License
121 stars 56 forks source link

Installation failure due to early import of external dependencies #22

Closed EwoutH closed 6 months ago

EwoutH commented 6 months ago

When attempting to install uxsim using pip install . or pip install -e ., the installation process fails during the phase where pip tries to get the requirements to build the wheel. This issue arises because the setup.py script indirectly imports the uxsim package, which in turn imports external dependencies such as numpy. Since these external dependencies are not yet installed at the point when setup.py is executed to determine the installation requirements, this results in a ModuleNotFoundError.

Steps to Reproduce

  1. Clone the uxsim repository or download the source code.
  2. Ensure that the environment does not have the dependencies (numpy, matplotlib, etc.) already installed.
  3. Run pip install . or pip install -e . from the root directory of the uxsim project.

You can also directly run:

pip install -U -e git+https://github.com/toruseo/uxsim@main#egg=uxsim

Expected Behavior

The pip install command should successfully install the uxsim package along with its specified dependencies without requiring them to be installed beforehand.

Actual Behavior

The installation process fails with a ModuleNotFoundError, indicating that one of the external packages (numpy is mentioned specifically) could not be found. This error is traced back to an import statement in the uxsim package that is executed as part of the setup.py script's execution.

Impact

This issue prevents the package from being installed in environments where the dependencies are not already present. It affects both development environments and end-users attempting to install uxsim for the first time, potentially limiting the adoption and usability of the package.

Workaround

A temporary workaround involves manually installing the dependencies listed in INSTALL_REQUIRES from the setup.py file before attempting to install uxsim. However, this approach is not ideal as it circumvents the automated dependency resolution and installation process provided by pip.

Suggested Fix

To resolve this issue, it is recommended to refactor the setup.py script and the package initialization process to avoid importing the package or any modules that require external dependencies. Instead, consider one of the following approaches:

Additional Information

This issue persists even when the dependencies are installed beforehand, indicating that the version fetching mechanism is inherently flawed and requires attention regardless of the installation environment.

You can see the full error message also here: https://github.com/EwoutH/UXsim/actions/runs/8110064753/job/22166521983

Related:

EwoutH commented 6 months ago

Hi @toruseo! I would like to use this package for my MSc thesis. I'm a maintainer of two open source libraries, so I can help implementing some best practices for packaging, deploying, testing and continuous integration.

This specific issue is particularly important to me, it needs to be build properly for all the other stuff to work and thus enable rapid iteration. So I'm glad to help out!

I understand however that maintenance of a libraries takes time and effort, so I'm curious on what your medium to long term vision is on this library. If you want to have a call sometime to discuss this please let me know!

EwoutH commented 6 months ago

If you're not able to spend much time on it, that's also fine, but then I might need to create my own fork. I don't prefer that, because I would like this library to grow based on the contributions of multiple people and keep the effort centralised.

toruseo commented 6 months ago

I think the problem is fixed now. Can you check?

Sorry for waiting. I am working on this project in my spare time, so my response may be delayed.

EwoutH commented 6 months ago

Thanks for working on it! I appreciate it, open-source work can be hard and demanding. Thanks!

I confirmed it fixed both in CI and locally!