2

I am using a machine I inherited with an Anaconda 3 installation on it. I am trying to complete a Python course, which is my first foray into Python ever. When I open a Python interpreter in Command Prompt or PowerShell, and I run the following line, it executes without error.

(base) PS D:\ProgramData\Anaconda3\Scripts> py
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlsxwriter

Somehow Anaconda is integrated with VS Code, yet when I try and import xlsxwriter in this window, I get the error:

ModuleNotFoundError: No module named 'xlslwriter'

When this Python interpreter window opens, it shows the following:

Jupyter Server URI: http://localhost:8889/?token=b8a07e61e603f9dae0ee599198ac33f68d3f398036f6af0e
Python version:
3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
(6, 0, 1)
D:\\ProgramData\\Anaconda3\\envs\\py37\\python.exe

If I try installing xlsxwriter with pip, I get a message that

Requirement already satisfied: xlsxwriter in d:\programdata\anaconda3\lib\site-packages (1.2.8)

I'm not asking for an instant answer, but guidance on how I can diagnose and correct this problem. Why is the module available to some interpreters (Command Prompt and PowerShell, and Jupyter Notebook) and not available in the VS Code interpreter? How can I use VS Code and or Python functionality to learn about the config of the current environment and such things?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • Have you noticed that you might be running 2 different Python versions? In the 1st case, your version is 3.7.4 and in the VS Code it is 3.7.6. Try running `which python` in both cases to check it. Is it possible that you use one environment in your shell and somehow VS Code uses other environment where the module is not installed? – Alex.Kh Apr 20 '20 at 03:24
  • @Alex.Kh Yes, it is highly possible likely I have 2 different environments, but I'm asking how can I diagnose why a module is only available to 1. How can I use pip to install the module package in the VSCode environment? BTW, how and where do I run `which python` please?: – ProfK Apr 20 '20 at 03:41
  • 1
    type `which python` in shell/terminal and in the VS Code terminal. It will tell you the path to the Python executable you are using. If they are different, you will clearly see that you are using different versions of Python. Also, run `conda env list` in terminal to check if you have more than 1 environment present/configured. As for Pip, check [this answer](https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment) for instructions – Alex.Kh Apr 20 '20 at 04:07
  • @Alex.Kh I get an error anywhere I try and run `which`. Is this a Linux command, as I am running Windows 10. I have since added a `Windows` tag. – ProfK Apr 20 '20 at 05:16
  • I came here because of a similar problem. At my case, telling because may help anyone doing the same silly mistake, had to do with the name of the file created and opened on VS Code. I was working with the Google API and named my file 'google.py'. Just needed to rename my file to avoid the conflict. – ChrCury78 Aug 18 '20 at 00:46

1 Answers1

1

Based on advice given in this answer, I ran the command

!pip install xlsxwriter

in the VS Code interpreter, and finally, the module was available for import.

ProfK
  • 49,207
  • 121
  • 399
  • 775