Python Venv: Module Not Found Error When Running in Cursor Terminal
Note: I cannot replicate the error in vscode, nor when activating the venv in a system terminal. Only in the Cursor terminal.
- If you can, please include a screenshot of your problem
- Error Message:
- Venv Modules List:
- Venv Python Paths:
- Please include the name of your operating system
- OS: Ubuntu 23.04
- HW: Virtualbox VM (7.0.10 r158379 (Qt5.15.2))
- Shell: ZSH (Although same error in bash as well)
- Python: Python 3.11.4
- If you can, steps to reproduce are super helpful
Steps to Reproduce
- In a Cursor workspace, open the command palette and search for:
Python: Create environment... - Create the python virtual environment:
./.venv/ - Ensure the venv is activated.
- Create a python script with a few non-standard libraries imported, i.e.
import pandas as pd,from flask import Flask - Attempt to run the script from within Cursor, and this is where the
ModuleNotFoundErrorcomes up.
The same happens to me but only with zsh, with bash it works fine. I also tried to replicate it on vscode and on an external terminal and it works fine on those cases, so I tend to think this is some problem with cursor.
With bash:
With zsh:
The problem in my case seems to be that for some reason sys.path and sys.executable and other sys.xx variables aren't properly configured for some obscure reason.
I'm also using pyenv for the base python installation and poetry for the dependencies.
This bug is kind of a showstopper, I have been using zsh since years ago
Same Here :(. Bash works...
Same problem with Zsh here. Any solution?
same problem with zsh...
Same issue here with zsh and quite annoying!
still open
Opening the terminal and running source ~/.zshrc is a good work-around, but it would be great if this can be solved.
This makes it very difficult to use cursor, as I use (and love) zsh. Any updates on a fix?
how this can be still a issue when its such a long time up here wow
Another way to walk around: use the remote ssh plugin to open your localhost folder in ssh, similar to how you are attaching cursor/vscode to a remote server (first make sure your ssh service is activated, can be checked by ssh localhost). In this case, you are only using a Cursor frontend and the cursor-server backend. zsh works well in this case
Another way to walk around: use the remote ssh plugin to open your localhost folder in ssh, similar to how you are attaching cursor/vscode to a remote server (first make sure your ssh service is activated, can be checked by
ssh localhost). In this case, you are only using a Cursor frontend and the cursor-server backend. zsh works well in this case
That should work, but for anyone who does this, make sure ssh is only binding on localhost or use a firewall 🙂
For me, manually installing the shell integration (instructions here) worked. I.e.,
- add
"terminal.integrated.shellIntegration.enabled": falsein Cursor'ssettings.json(mandatory) - add the following to your
~/.zshrcfile:[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
I have VSCode installed as well, if you don't, the command in the second step will not work.
2.
[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
this didnt work for me
For me, manually installing the shell integration (instructions here) worked. I.e.,
- add
"terminal.integrated.shellIntegration.enabled": falsein Cursor'ssettings.json(mandatory)- add the following to your
~/.zshrcfile:[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"I have VSCode installed as well, if you don't, the command in the second step will not work. This worked for me.
Just to give more context if anybody with the same setup steps into this issue:
I use pyenv and poetry (with virtualenvs.prefer-active-python set to true) to manage all my venvs and was not able to use cursor's integrated terminal, always having ModuleNotFoundError when running python commands, even though the dependencies were installed with poetry in the pyenv virtualenv correctly and the venv activated. But everything worked as expected using my terminal with zsh.
I couldn't run step 2 because my vscode is installed through snap, code needs to be in your $PATH to run this, according to the instructions link in the answer.
But only the first step was necessary to solve the issue for me. Now my cursor integrated terminal is working fine. Thanks!
Does not work for me. Having these two lines in the ~/.config/Cursor/User/settings.json:
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.shellIntegration.enabled": false,
and also having this line
[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
in my .zshrc
But still, the modules are not found. The virtualenv is definitely activated.
It only works when I swich the defaultProfile to tmux, but I don't like this shell (especially how it catches the mouse wheel to scroll through the history)
I have same problem
I have same problem with ZSH
Same problem with zsh here. None of the solutions I found in discussions seems to fix the problem permanently; sometimes they work, sometimes they don't!
Similar problem here, using cursor V1.0.0 and zsh in linux mint 22.1:
Cursor is useless for python on linux as appimage does not work with virtual environments. Stop distributing your app as an appimage please.
into ~/.zshrc
# FIX CURSOR start
python_venv() {
MYVENV=./.venv
# when you cd into a folder that contains $MYVENV
[[ -d $MYVENV ]] && source $MYVENV/bin/activate > /dev/null 2>&1
# when you cd into a folder that doesn't
[[ ! -d $MYVENV ]] && deactivate > /dev/null 2>&1
}
# autoload -U add-zsh-hook
# add-zsh-hook chpwd python_venv
[[ "$TERM_PROGRAM" == "vscode" ]] && python_venv
# FIX CURSOR end
thank you @moshe-parametrix for this workaround. i use a venv that is outside of the working tree so i have .zshrc attempt to find it via .vscode/settings.json
VSCODE_PYTHON_PATH=$(jq -r '."python.defaultInterpreterPath" // empty' .vscode/settings.json 2>/dev/null)
if [[ -n "$VSCODE_PYTHON_PATH" && -f "$VSCODE_PYTHON_PATH" ]]; then
MYVENV=$(dirname "$VSCODE_PYTHON_PATH")
MYVENV=$(dirname "$MYVENV")
fi
[[ -d $MYVENV ]] && source $MYVENV/bin/activate > /dev/null 2>&1
I'm having exactly the same issue as descriped by the OP, and it's caused by what is exaplained here: https://github.com/cursor/cursor/issues/792#issuecomment-1694772947
I seem to be running the venv python but it cannot find the packages because of the sys issues.
I compared the set variables between zsh session that has issues and session that does not and concluded that the root cause is ARGV0 variable being set by Cursor when initializing terminal. I'm not entirely sure why it does it - ChatGPT suggests it may be needed for integrating with IDE.
Now, the point is that as soon as I unset this variable my venv python stopped complaining about missing packages.
I'm not keen on removing the variable, so as a workaround I'm using env -u ARGV0 to run python commands in the affected sessions.
So I proceeded to create AGENTS.md and added the following section:
## Python
### Virtual Envs
1. Use venv for managing python virtual environments
2. When you work on a tool/script, first check for the presence of venv then initialize the environment before running other commands - that is, avoid initializing the env and running a python command in the same statement
3. When running python commands use `env -u ARGV0` - this is a workaround for a Cursor's terminal issue that causes python runtime to not see venv packages
4. If python is wrapped in shell scripts run those with `env -u ARGV0` as well if you notice python complaining about not installed packages
I hoped it will get picked up immediately but atm I still need to manually add AGENTS.md to the chat context. BUT I was finally able to get the agent to run venv python:
Pandas is installed. Let me try using the env -u ARGV0 workaround as mentioned in the AGENTS.md file