spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.3k stars 1.61k forks source link

Spyder 5 install cannot import pip installed modules #17141

Closed xspam1984 closed 2 years ago

xspam1984 commented 2 years ago

Description

What steps will reproduce the problem?

in fresh version of spyder 5 download to a system that already had spyder 4.

Using the ipython console command:

!pip install selenium

Spyder sucessfully identifies that selenium is already installed on system

import selenium yields ModuleNotFoundError: No module named 'selenium'

importing works in old spyder 4 version.

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree                  :  None (OK)
IPython >=7.6.0               :  7.30.1 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.8.9 (OK)
jsonschema >=3.2.0            :  4.2.1 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.3.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.8.1 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.0.1 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.2 (OK)
qtpy >=1.5.0                  :  1.11.3 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  59.6.0 (OK)
sphinx >=0.6.6                :  4.3.1 (OK)
spyder_kernels >=2.2.0;<2.3.0 :  2.2.0 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog                      :  2.1.6 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.25 (OK)
matplotlib >=2.0.0            :  3.5.1 (OK)
numpy >=1.7                   :  1.19.3 (OK)
pandas >=1.1.1                :  1.3.5 (OK)
scipy >=0.17.0                :  1.7.3 (OK)
sympy >=0.7.3                 :  1.9 (OK)
ccordoba12 commented 2 years ago

Hey @xspam1984, thanks for reporting. You said:

!pip install selenium

This is probably installing selenium in another Python environment different from the one that comes with our installer because the installer doesn't come with pip. The reason for that is to avoid people breaking Spyder when installing other packages that conflict with it.

To learn how to use packages that don't come with our installer, please read this FAQ in our docs.

ccordoba12 commented 2 years ago

Closing due to lack of response.

xspam1984 commented 2 years ago

ccordoba12's comment sent me off on the right path. I originally installed Spyder through Anaconda navigator. Updating spyder might have added or changed my environment so that it wasn't aligned with anaconda anymore.

Things started to click for me by adjusting my environments in Anaconda Navigator as suggested in Stackoverflow issue 30170468

If I launch spyder through anaconda navigator, and select my environment for Spyder (which was created I think during an update spyder/anaconda navigator prompt) then everything starts to play nicely again.

Near as I can tell... !pip listens to anaconda navigator instead of any internal spyder setting (partially as was noted up above). Issue is resolved successfully. Thanks for the help!

capitanevs commented 1 year ago

Hey @xspam1984, thanks for reporting. You said:

!pip install selenium

This is probably installing selenium in another Python environment different from the one that comes with our installer because the installer doesn't come with pip. The reason for that is to avoid people breaking Spyder when installing other packages that conflict with it.

To learn how to use packages that don't come with our installer, please read this FAQ in our docs.

Hi, I just wen through a similar issue (spyder can not read modules installed with pip install) and I found this post (with quite an effort).

I understand the reason of not breaking Spyder installation, sounds great!. I would just share two comments

In the ends the comments were 3 :-)

Thanks for reading.

C

ccordoba12 commented 1 year ago

Understanding the reason of my "ModuleNotFound" error was quite a pain. How about adding a disclaimer to the warning message, explicitely mentioning PyPi-ware as a possible origin of the error?

We already show a message that points to our documentation to tell users what they need to do to use other modules that don't come with our installers:

imagen

I found that the best practice solution at this link is quite sophisticated, especially for basic spyder/python users. After all PyPi is the most popular python packages repository: is it really good that accessing to it has such a high activation cost? Isn't there another way to go through that?

We're working to provide a graphical way to create conda environments, install packages on them and automatocally connect them to Spyder (pip is not really good at solving dependencies for packages, so we don't plan to use it for that). That work will be available for our Windows and macOS installers when Spyder 6 is released next year.

I have seen workarounds on the web, e.g. adding the pypi packages folder to spyder paths. This worked for me, and it is actaully much easier than playing with environments. Isn't it risky that workarounds "seem" so much smoother and seducing than the "right way"?

The right way is using a different environment. Hacks like the one you mentioned only work for pure Python packages (e.g. Flask), not for complied ones (e.g. Numpy, Pandas or Matplotlib) because they are binary incompatible between Python versions.

capitanevs commented 1 year ago

Thanks for all the answers! 1) Lovely warning, exactly what I dreamt of :))) I guess I just have to update to latest versione

2) This sounds really great. Just one more curiosity: By means of pip, everyone can easily distribute their own packages. Will this be possible again in a simple way? (it seems to me that you would like to make conda environments easier to create, but the fact that you are planning to exclude pip confuses me. Sorry if the question sounds as silly :)

3) Got it! Definitely a must-know!

Tnx!

capitanevs commented 1 year ago

Hi Guys,

I don't want to sound pushy but.... the fact that spyder can't easily load modules from pypi is becoming more and more addictive to the extent that I'm using python for "leisure" (i.e. not for work), which IMO is one of the noblest reasons why one can approach programming ;-)

For example. I just wanted to copy and paste some text into the win clipboard, and the the GPT3 chatbot (which is getting more and more popular in supporting earlier programmers) directed me to two packages that are both not present in the conda distro:

immagine

I was just wondering if being disconnected from pypi choice is driving newbies away from spyder (or maybe improving learning to use python environments ;-)

In any case, thank you for the great effort you are doing for making spyder grow: I understand that concealing all the needs in a professional way is not easy.

Also: how can I discover what is the latest distro of anaconda where spyder is still linked to pypi?

Tnx