I have created a conda environment named "pino" by:
conda create -n pino
Then, I installed the python 3.8 and pytorch in pino.
I did activate pino in the build-in terminal by
conda activate pino
And the terminal has shown:
(pino) jipengcui inform %
To test whether the installaton of pytorch is successful, I created a python file named 'test.py':
import torch
print("done")
Then, I have tested it in 3 different ways.
- Debug in VS code.
It worked and shown result:
done - Test it in VS code build-in terminal(
zsh) by run:
python3 run test.py
It didn't work and provided information:
Traceback (most recent call last):
File "/Users/jipengcui/Documents/3_vs_code/physics_informed/test.py", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
- Test it in MacOS terminal(
zsh) by run:
python3 test.py
It shown the result:done
The launch.json is:
{
"configurations": [
{
"name": "Python Debugger: Python File",
"type": "debugpy",
"request": "launch",
"program": "${file}"
}
]
}
And the setting.json is:
{
"workbench.settings.applyToAllProfiles": [
],
"terminal.integrated.shell.osx": "/bin/zsh",
"workbench.editor.enablePreview": false,
"terminal.integrated.defaultProfile.osx": "zsh",
"python.autoComplete.extraPaths": [],
"python.analysis.extraPaths": [],
"python.terminal.activateEnvironment": false,
"python.condaPath": "/opt/anaconda3/envs/pino/share/man/man1/python3.1"
}
Why the code could run in original terminal and could not run in VS Build-in terminal? How to fix it? Please!
1 Answer 1
Thank you all. The problem has been fixed refer to Common questions
-terminal profile. As depicted in the common question:
standalone macOS terminals all run as login shells by default, since macOS does not run a login shell when the user logs into the system.
Then, with "terminal.integrated.inheritEnv": false added to setting.json, the problem was fixed.
zshcould run but could not in VS code build-in terminal. I'm sorry I couldn't provide more information since I have not enough reputation.baseis 3.12 and in thepinois 3.8. My question is, if VS use one while teminal use the other, how it could run in terminal inzshand could not in VS build-in terminal?