简体   繁体   中英

Numpy cannot be accessed on Jupyter. Is it a problem with the path and how do I fix that?

This is probably a very basic question but I have not been able to solve it for some time.

My goal is to start using Python with Jupyter Notebook for data analytics.

I first downloaded Python 3.7 on OSx10.95. Then tried to download Anaconda, wich failed a few times. Then I downloaded Miniconda and used Wing101. After that I could download Anaconda. However, I did not get Anaconda navigator to work.

Then I started using Jupyter Notebook from terminal. It works but there are a number of problems:

In Jupyter when I try to import pandas and numpy I get an error:

--------

<ipython-input-1-baf368f80de7> in <module>
----> 1 import pandas as pd
      2 import numpy as np

~/anaconda3/lib/python3.7/site-packages/pandas/__init__.py in <module>
     17 if missing_dependencies:
     18     raise ImportError(
---> 19         "Missing required dependencies{0}".format(missing_dependencies))
     20 del hard_dependencies, dependency, missing_dependencies
     21 

ImportError: Missing required dependencies ['numpy']

----------

Numpy is installed though, but it is probably in the wrong place.

Another problem is that the Anaconda and Python files are all over my computer:

The Anaconda navigator is at:

/anaconda3

Pip 3.7 is at:

/Library/Frameworks/Python.framework/Versions/3.7/bin/

Numpy is at:

/Users/lsluyser/Downloads/ENTER/lib/python3.7/site-packages/pandas/compat/

Jupyter files are at:

/Users/lsluyser/Downloads/ENTER/lib/python3.7/site-packages/

and also at:

/anaconda3/lib/python3.7/site-packages

My question is: What is the desired organization of the program files and how do I achieve this? Should I move all files from Downloads to another folder? Should numpy be put under /anaconda3/lib/python3.7/site-packages? Can the fact that Anaconda navigator does not work have to do with its location?

Thank you very much in advance! Lotte

I suggest using Miniconda, which is a smaller alternative to Anaconda. Even if you don't, you should download the packages you need, such as numpy, from Anaconda Cloud , which should put the files in proper location.

Generally [on Windows] the packages should be in folder C:\\Users\\<>\\Miniconda3\\Lib\\site-packages and verify the environment variable has necessary paths.

If you're going to work in Python, you will soon realize the need for creating multiple python virtual environments on your computer. This is because, when working in Python:

  1. You will constantly run into situations that require you to install, upgrade, or downgrade some new module.
  2. Each such install, upgrade, or downgrade could have some unwanted side-effect (something that was working earlier, stops working after the change).
  3. By creating multiple virtual environments, you will be able to perform such installs, upgrades or downgrades within a specific environment, with no risk of affecting your other environments.

Tools such as Anaconda and Miniconda make it easy for you to create and manage such virtual environments.

Under the hood, the creation and management of the virtual environments is probably not much more than setting some environment variables.

I found this to be a good intro to the concept.

For your problem, yes, most likely your problem with numpy can be solved by suitably setting environment variables, but I would suggest not to attempt that.

Instead, use Anaconda or Miniconda to create an environment, and within that environment, use Anaconda or Miniconda to install numpy. You will of course will be prompted about any pre-requisites that may be needed for numpy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM