简体   繁体   English

无法在Jupyter上访问Numpy。 路径有问题吗?该如何解决?

[英]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. 我的目标是开始在Python和Jupyter Notebook中使用Python进行数据分析。

I first downloaded Python 3.7 on OSx10.95. 我首先在OSx10.95上下载了Python 3.7。 Then tried to download Anaconda, wich failed a few times. 然后尝试下载Anaconda,但失败了几次。 Then I downloaded Miniconda and used Wing101. 然后,我下载了Miniconda,并使用了Wing101。 After that I could download Anaconda. 之后,我可以下载Anaconda。 However, I did not get Anaconda navigator to work. 但是,我没有让Anaconda导航器正常工作。

Then I started using Jupyter Notebook from terminal. 然后我从终端开始使用Jupyter Notebook。 It works but there are a number of problems: 它有效,但是存在许多问题:

In Jupyter when I try to import pandas and numpy I get an error: 在Jupyter中,当我尝试导入pandas和numpy时出现错误:

--------

<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. 虽然安装了Numpy,但是可能在错误的位置。

Another problem is that the Anaconda and Python files are all over my computer: 另一个问题是Anaconda和Python文件遍布我的计算机:

The Anaconda navigator is at: Anaconda导航器位于:

/anaconda3

Pip 3.7 is at: 3.7点位于:

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

Numpy is at: numpy位于:

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

Jupyter files are at: Jupyter文件位于:

/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? 是否应将numpy放在/anaconda3/lib/python3.7/site-packages?/anaconda3/lib/python3.7/site-packages? Can the fact that Anaconda navigator does not work have to do with its location? Anaconda导航器不起作用的事实是否与其位置有关?

Thank you very much in advance! 提前非常感谢您! Lotte 乐天

I suggest using Miniconda, which is a smaller alternative to Anaconda. 我建议使用Miniconda,它是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. 即使您不这样做,也应该从Anaconda Cloud下载所需的软件包,例如numpy,这会将文件放置在正确的位置。

Generally [on Windows] the packages should be in folder C:\\Users\\<>\\Miniconda3\\Lib\\site-packages and verify the environment variable has necessary paths. 通常,[在Windows上]软件包应位于文件夹C:\\ Users \\ <> \\ Miniconda3 \\ Lib \\ site-packages中,并验证环境变量是否具有必需的路径。

If you're going to work in Python, you will soon realize the need for creating multiple python virtual environments on your computer. 如果您要使用Python工作,您很快就会意识到需要在计算机上创建多个python 虚拟环境 This is because, when working in Python: 这是因为在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. Anaconda和Miniconda等工具使您可以轻松创建和管理此类虚拟环境。

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. 对于您的问题,是的,很可能可以通过适当设置环境变量来解决numpy的问题,但我建议不要尝试这种方法。

Instead, use Anaconda or Miniconda to create an environment, and within that environment, use Anaconda or Miniconda to install numpy. 而是使用Anaconda或Miniconda创建环境,并在该环境中使用Anaconda或Miniconda安装numpy。 You will of course will be prompted about any pre-requisites that may be needed for numpy. 当然,系统会提示您有关numpy可能需要的任何先决条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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