Pip可编辑模式下出现‘Module not found’问题求助
Let’s tackle this issue—since your project runs fine when installing dependencies via requirements.txt, but breaks when using pip install -e on the newVersion branch of entity-fishing-client, the problem is rooted in how that branch handles editable installs. Here’s how to fix it:
1. Validate the Branch’s Build Configuration
Editable installs depend entirely on the package’s setup.py (or pyproject.toml) to map files to module names. The newVersion branch might have a misconfigured build file that breaks this mapping:
- Double-check that the
nameparameter insetup.pymatches exactly what your project imports. For example, if your code usesimport entity_fishing_client, the setup file should declarename="entity-fishing-client"(or the corresponding correct module name). - Confirm the
packageslist insetup.pyincludes all the necessary module directories. If the branch restructured the code but didn’t update this list, pip won’t know where to find the module files. Try runningpython setup.py developdirectly in your clonedtestDependencyfolder—this will often spit out explicit errors about missing packages thatpip install -ehides.
2. Double-Check Your Virtual Environment Context
It’s easy to mix up environments or have the editable install not link properly to your venv:
- Make sure you’re activating the same
venv3environment both when runningpip install -eand launching your Bottle server. - Run
pip listinvenv3to confirmentity-fishing-clientshows up with(-e ../testDependency/)next to it—this proves the editable link was created correctly.
3. Refresh the Editable Install
Corrupted symlinks or stale build files can break editable installs. Let’s reset it:
- Uninstall the package first:
pip uninstall entity-fishing-client - Clean up leftover build artifacts in
testDependency:rm -rf build/ dist/ *.egg-info/ - Reinstall in editable mode:
pip install -e ../testDependency/ - Restart your Bottle server (and any Python shells) to clear the module cache.
4. Check Module Structure and Path Sensitivity
If the newVersion branch changed the directory structure, that could throw off imports:
- Verify the cloned
testDependencyfolder has a module directory (with an__init__.pyfile) that matches your import path. For example, if you usefrom entity_fishing_client import ..., there should be a folder namedentity_fishing_clientwith that init file. - On macOS/Linux, case sensitivity matters—if the branch renamed the folder to
EntityFishingClientbut your code uses lowercase, that’ll cause a module not found error even if the files look correct.
5. Isolate the Issue with a Direct Import Test
To rule out your project as the source, launch a Python shell in venv3 and try importing the module directly:
import entity_fishing_client print(entity_fishing_client.__file__)
If this throws an error, the problem is definitely with the newVersion branch’s editable install setup. If it works, then your project might have a sys.path modification that’s overriding the venv’s installed packages—check for any code that modifies sys.path in RootPage.py or related files.
内容的提问来源于stack exchange,提问作者Luca Foppiano

