spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Spyder profiler uses wrong python when using virtualenv

Open 22csnyder opened this issue 9 years ago • 9 comments

I have cross posted this from https://code.google.com/p/spyderlib/issues/detail?id=2209&thanks=2209&ts=1429797280

Spyder Version: 2.2.5 Python Version: 2.7.6 Qt Version : 4.8.6, PyQt4 (API v2) 4.10.4 on Linux pyflakes >=0.5.0: 0.8.1 (OK) pep8 >=0.6 : 1.4.6 (OK) IPython >=0.13 : 1.2.1 (OK) rope >=0.9.2 : 0.10.2 (OK) sphinx >=0.6.6 : 1.2.2 (OK) matplotlib >=1.0: 1.3.1 (OK) sympy >=0.7.0 : None (NOK) pylint >=0.25 : 1.1.0 (OK)

What steps will reproduce the problem? 1.In preferences>console>advanced, set the python interpreter to a virtual environment interpreter e.g. /home/christopher/.virtualenvs/wormvision2/bin/python2.7

  1. Run some code that uses a module only visible to the specified interpreter, but not to the /usr/lib/ interpreter.

What is the expected output? What do you see instead? Expected it to work fine.

Instead got: Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals .. from sklearn.cluster import KMeans ImportError: No module named sklearn.cluster

As you can see, it's trying to find sklearn with /usr/lib interpreter, which is not possible because I have never installed that globally. However, it is installed locally in the virtual env, which works fine with f5.

Please provide any additional information below. Merely running the script (F5) works fine. F10 produces the above error.

22csnyder avatar Apr 29 '15 01:04 22csnyder

@dhoegh, could you take a look at this problem when you have some time?

ccordoba12 avatar Apr 29 '15 16:04 ccordoba12

I had a thought last night that it might have to do with whether --with-site-packages is allowed on the VirtualEnv or not. I haven't had a chance to dig into it though

22csnyder avatar Apr 29 '15 16:04 22csnyder

I am on Spyder 4.0.0b3 running in a separate env (spyder) for dependency reasons. The code i develop runs in env (dev). The python interpreter is set to the (dev) in spyder preferences. However it seems the profiler is still using (spyder) env, which of course throws me errors. Any news on this bug?

lrachbau avatar Jul 03 '19 12:07 lrachbau

I am on Spyder 4.0.0b3 running in a separate env (spyder) for dependency reasons. The code i develop runs in env (dev). The python interpreter is set to the (dev) in spyder preferences. However it seems the profiler is still using (spyder) env, which of course throws me errors. Any news on this bug?

Same behavior with Spyder 3.1.3

DanielSastoque avatar Sep 01 '19 19:09 DanielSastoque

Same behaviour with Spyder 4.1.4.

milindsmart avatar Jul 21 '20 09:07 milindsmart

I still experience this issue with Spyder 4.2.1

guidomeijer avatar Jan 05 '21 14:01 guidomeijer

Is there any update in regard to this issue? I still experience it on with Spyder 4.2.3

j-eser avatar Mar 13 '21 18:03 j-eser

Any updates on this?

Is it because pythonpath isn't being set up properly?

I haven't looked into what these variables mean but it looks to me like env gets created before pythonpath gets added in, and that that's what's used for the profiler. But I may be misunderstanding.

https://github.com/spyder-ide/spyder/blob/master/spyder/plugins/profiler/widgets/main_widget.py#L534

Christophe-Foyer avatar Jan 31 '22 13:01 Christophe-Foyer

This will be fixed in Spyder 6, to be released at the end of the year or the beginning of the next one.

That's because the changes to do it are not so simple, so we can't include them in Spyder 5, sorry.

ccordoba12 avatar Jan 31 '22 14:01 ccordoba12