3

For some reason when I install a package through Anaconda, it is not available in Spyder. When I execute the following command in anaconda and in spyder I get different files.

Anaconda:

import sys; sys.executable
'C:\\Users\\onp1ldy\\AppData\\Local\\conda\\conda\\envs\\deeplearning\\python.exe'

Spyder:

import sys; sys.executable
'C:\\Users\\onp1ldy\\AppData\\Local\\conda\\conda\\envs\\deeplearning\\pythonw.exe'

Can anyone help me with this? I am not sure what to do...

mickNeill
  • 346
  • 5
  • 22
  • I'm not sure the problem is with python and pythonw because of [this](https://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe), Do you have more than one python version installed ? If yes which one comes first in the PATH ? – RMPR Oct 22 '19 at 07:53
  • I don't have python in PATH. I installed Anaconda/Spyder, and python comes with it. I also installed the package - torch - through Anaconda Prompt (run with administrator rights). When run in the Anaconda Prompt console, the package is included and I am able to use it without error; when I include it in Spyder, it is included, but it gives error at the same operation used in console "'torch' has no attribute rand :/" – Ileana Profeanu Oct 22 '19 at 08:33

3 Answers3

2

By Default: You can control which one of the executables will run your script. Such as, when opened from Explorer by choosing the right file_name like:

1. python.exe is a terminal-based (console) application to run and lunch CLI-Type Python-scripts.

*.py files are by default associated (invoked) with python.exe

2. pythonw.exe is a GUI-based app for lunching Graphical User interface-(No_UI_at_all_Scripts)

*.pyw files are by default associated (invoked) with pythonw.exe

TO SUMMARIZE AND COMPLEMENT MY OPINION:

First of all, Python-Binary that you're trying to run doesn't have Package installed. It does have a directory path named as package_name like torch at the search path of modules, and it is being treated as a Package namespace like for me:

torch.Tensor(5, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'torch' has no attribute 'Tensor'

For your current python binary, you need to install your package correctly. Visit Reference: Home-Page

python3.7 -m pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl 
python3.7 -m pip install torchvision

More importantly, replace the pip or pip3 as the Home-Page instructions use with python3.7 -m pip;. In the end, don't forget to include python3.7 to be the full path to your Python binary.

Muhammad Usman Bashir
  • 1,441
  • 2
  • 14
  • 43
0

Run this in spyder and see if you can access the package.

import subprocess

subprocess.call('pip install numpy', shell=True)

import numpy
Sachin Prabhu
  • 152
  • 2
  • 11
0

based on your description the problem may be connected to the Python interpreter that you are using in Spyder. There is a similar issue on Stack Overflow at this url:

Issue on Anaconda and Spyder

You can try the solution proposed by Bremsstrahlung.

Hope this can help you.

Andrea Grioni
  • 187
  • 1
  • 9