Cursing Cursor

Took me a week or so to figure out a weird bug with the Cursor IDE and python virtual environments. This post might help someone else with the same issue out there.
Open Source
Artificial Intelligence
Python
Author

Andrew Lis

Published

September 22, 2024

Welp.

Seems like basically every single week there’s some kind of “latest and greatest” Ai thing coming out.

I’m fascinated by the possibilities the technology offers, and I truly believe it will rank among the biggest technological leaps in history, similar to the birth of the internet.

But as with any maturing technology, there will be many ups and downs along the way.

And quite probably, a lot bugs.

Case in point: Cursor

First Impressions

When I saw my various social media feeds start buzzing about a new Integrated Development Environment (IDE) called Cursor, my first reaction was to dismiss it and file it among all the other “Ai-hype trash” there seems to be so much of these days.

But after seeing a few posts of some people in the coding world I respect using it, and actually liking it, I thought: “I should probably kick the tires on this thing”.

Being on Manjaro, I grabbed the latest version available on the AUR, and was fairly surprised to find it loaded up without any issue.

But then, I loaded up some python projects I’ve been meaning to work on, and that’s when I ran into an issue that took me a while to figure out.

The Missing Path

It seems that (in my case), setting up a python project with a virtual environment doesn’t work like it does in VS Code.

Which is odd, since Cursor is really just a fancy Ai-enabled fork of VS Code.

Typically, you just have to create folder for your project, load up the IDE (opening the folder), then create a virtual environment, and you should be good to go.

With Cursor, following all the usual steps gets you to a point where everything should be working, but when you try to import any non-standard python module in your python script, you’ll get hit with a ModuelNotFoundError.

:-(

Solved At Last!

At this point, I still don’t fully understand why this happens, but I do have a workaround for anyone out there who might be trying to figure this out.

It seems that Cursor doesn’t properly set the path to the virtual environment (venv) modules, which appears to be why the ModuelNotFoundError arises.

If you’re having this issue, if you type and execute the following in a python script, you’ll notice the paths may not exactly match where your venv has stored the python modules:

import sys

print(sys.path)

For example, if you pip install the plotly dash module to your venv, you’ll be able to see it in the .venv/lib/ folder.

But when you try to load it using import dash, you’ll get the ModuelNotFoundError.

When you use pip list, you’ll see that dash is indeed installed to your venv.

But, the issue, is where it has been installed!

If you run pip show dash, and take note of the exact file path shown by the Location output line, you might see something like this:

/home/user/my_folder/CURSOR_PYTEST/.venv/lib/python3.12/site-packages

Your username will be different, and in this example, the python script is located in the my_folder/CURSOR_PYTEST directory.

So, the solution/workaround is to set this path in your python session, using:

import sys

sys.path.append('/home/user/my_folder/CURSOR_PYTEST/.venv/lib/python3.12/site-packages')

Now, when you call import dash, you should be good to go.

Working Out The Kinks

I’ve never had to use the procedure described above in VS Code, and while it’s possible I’m doing something wrong on my end, my gut feeling is that this issue is a bug with Cursor.

At the time of writing, I’m running Cursor version 0.41.2, and I’ve noticed there’s a few other folks who’ve had this issue lurking around the internet, so hopefully the good folks at Cursor figure it out and fix it eventually.

In the meantime, I’m going to (finally) kick the tires on Cursor, and I’ll maybe do another post with some thoughts/impressions after having used it for a while.