2

First, I've looked through other people's questions that sound similar and haven't found a situation like mine. If you know of another post that solves my problem, I'm all ears (eyes, whatever).

I have been using Spyder through Anaconda for most of my Python work up to now, but I don't really like it that much. So, I'm trying to explore other IDEs, currently Atom. I have set up Atom and cmd.exe to run Python from the Anaconda install by adding the .\Anaconda3 folder to my path. I have also added the .\Anaconda3\Lib\site-packages and everywhere else I have found that anaconda has stored its modules (within the base environment).

Python runs fine in the Command Prompt and in Atom (using "script" package), but for some reason I cannot import any modules except sys and os unless I use either the Anaconda terminal or one of its included IDEs. I can't even import numpy, though I can navigate to the site-packages folder in File Explorer and see it in there. Below is a screen shot showing side-by-side the Anaconda Prompt and Command Prompt. You can see that my path variable and executable are the same in both, but conda imports numpy just fine while cmd cannot. I would like to know why and how to fix it. All of the other questions I saw of this issue (StackOverflow and elsewhere) said to add the file path to the module to my PATH variable (which I have done) or run the program using the Anaconda executable (which I am doing).

Command Prompt vs Anaconda Prompt exectuable, path variable and importing numpy

Also, I searched for the ImportError (shown in the picture) on the internet and found a link to the Anaconda documentation saying to check the System32 folder for mkl related dll's but there weren't any in mine. Then I looked through the _distributor_init.py file in the numpy folder to figure out where it was trying to pull the _mklinit function from and see if maybe it was looking somewhere different from Anaconda. But if I understand correctly the "from . import" means that it's looking in the same numpy directory for that function and there is a file in there called _mklinit.cp37-win_amd64.pyd (which I can't look at the contents of, but it seems like a good candidate to me). In any case, it seems like it looks in the same location for both Command Prompt and Anaconda Prompt, so that didn't help either.

I was going to install Python separately from Anaconda, but I've heard that I can cause problems for myself unless I know what I'm doing (which I don't). So, I would like to do this by just accessing the packages that Anaconda has, which everyone keeps saying I can do but it isn't working for me so far.

It's possible I'm dumb, but I don't get it. Any help would be appreciated.

Running:

Windows 10

Python 3.7.4

Anaconda 4.8.3

rustic1112
  • 21
  • 2
  • Hi @rustic1112, welcome to Stack Overflow. It looks like you're trying to run python from Anaconda without using any conda virtual environments, (including the conda base environment). Anaconda relies heavily on this in order to let you manage different Python environments and package versions without worry of dependency conflicts – bug_spray May 18 '20 at 14:26
  • To enter the base conda environment from the terminal, usually you have to do something like `source anaconda3/bin/activate` or `. anaconda3/bin/activate` depending on your shell. After that, you need to do `conda activate myenv` to enter an environment (arbitrarily) named *myenv* that you've already created. Also from the base environment, you can create conda environments by doing stuff like `conda create -n myenv python=3.7`, and you can exit environments with `conda deactivate`. – bug_spray May 18 '20 at 14:34
  • Assuming you're familiar with all of this, you would need to set up your IDE with the path of your desired conda environment, such as `~/anaconda3/envs/myenv/bin/python`, assuming your desired conda environment is called *myenv*. The IDE should then have access to all packages installed in that particular conda environment, and use that particular version of Python. – bug_spray May 18 '20 at 14:34
  • According to [this post](https://stackoverflow.com/questions/43207427/using-anaconda-environment-in-atom), things may be a bit different for setting anaconda up with Atom. For setting things up in Pycharm, see [here](https://docs.anaconda.com/anaconda/user-guide/tasks/pycharm/). Alternatively, you could use any IDE you want, and run your python files from the terminal (in the correct conda environment), by doing `python myfile.py` for some file *myfile.py*. – bug_spray May 18 '20 at 14:44

1 Answers1

0

I've been trying to work this out for sometime. My Anaconda Python is 3.8. Before installing Anaconda I had Python 3.9 installed. I sometimes wanted to use my 3.9 Idle but pip always put added packages into Anaconda. The Python Documents tell you how. file:///Library/Frameworks/Python.framework/Versions/3.9/Resources/English.lproj/Documentation/installing/index.html.

In my MacBook Pro Terminal I entered (as an example). It worked.

python3.9 -m pip install torchvision

Arnold
  • 153
  • 1
  • 9