I'm developing in python inside a Conda environment. All the packages I add to the environment can be imported successfully when running the "python" binary created under the environment. However, when trying to debug with pdb any of my python scripts I would get ImportError for the very same packages.
For example, after creating a new environment and adding the following packages
pip install keras
pip install conection
I run the following test.py script
import keras
import connexion
print("I have imported keras alright")
print("I have imported connexion alright")
from keras.models import Sequential
from keras.layers import Dense, Activation
# for a single-input model with 2 classes (binary):
model = Sequential()
model.add(Dense(1, input_dim=784, activation='softmax'))
print("I have defined a keras network alright")
This works alright when invoking it the usual way,
python test.py # Works OK
but fails when running in debug mode in pdb
pdb test.py # ImportError: No module named connexion
The question is: how can pdb be properly configured to work with the packages that were installed in the conda environment?
Additional info: while the python binary is indeed in the conda environment
which python # returns $HOME/miniconda3/envs/$USER/bin/python
pdb seems to always refer to the system version
which pdb # returns /usr/bin/pdb
Alternatively, use python3 -m pdb <script>
to use pdb with conda and python 3
Copy pdb
executable to your environment, and set the shebang (first line) from #!/usr/bin/python
to #!/usr/bin/env python
. If you want this to be the default behavior for any environment (including the system pdb), you can change the shebang only in /usr/bin/pdb
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With