我厌倦了尝试为phyton 2.7.5安装numpy和scipy,我需要这个版本的python,因为我的最终目标是安装类(http://class-code.net/)和montepython(http://montepython.net/).

(我有ubuntu 12.04)

当我尝试导入numpy或scipy时,我每次都会收到以下错误:

$phyton2.7

>>> import numpy

Traceback (most recent call last):

File "", line 1, in

File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in

import add_newdocs

File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in

from numpy.lib import add_newdoc

File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in

from type_check import *

File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in

import numpy.core.numeric as _nx

File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in

import multiarray

ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

>> import scipy

Traceback (most recent call last):

File "", line 1, in

File "/usr/lib/python2.7/dist-packages/scipy/__init__.py", line 78, in

from numpy import show_config as show_numpy_config

File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in

import add_newdocs

File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in

from numpy.lib import add_newdoc

File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in

from type_check import *

File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in

import numpy.core.numeric as _nx

File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in

import multiarray

ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

为了摆脱我曾尝试过的错误:

>满足python要求:$sudo apt-get install build-essential python-dev gfortran

>使用apt-get安装:$sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

>使用pip安装需求:$sudo pip install requests

> …并尝试使用pip进行安装:$sudo pip install numpy和$sudo pip install scipy

>我已经有环境var:export PYTHONPATH = /usr/lib / python2.7 / dist-packages:${PYTHONPATH}

我最后一次安装numpy和scipy(在较旧的ubuntu 10.x版本中)这对我有用.

> sudo sh -c“wget http://python-distribute.org/distribute_setup.py -O- | python”sudo sh -c“wget https://raw.github.com/pypa/pip/master/contrib/ get-pip.py -O- | python“然后使用pip安装它们,如(4)中所示

但现在看来python-distribute.org的服务器已关闭.我收到以下错误:

http://python-distribute.org/distribute_setup.py

Resolving python-distribute.org (python-distribute.org)... failed: Name or service not known.

wget: unable to resolve host address `python-distribute.org'

>我还尝试从synaptic和Ubuntu软件中心安装numpy和scipy

我在每次尝试中都失败了,现在我不知道该怎么办.

我错过了什么吗?

如何为python正确安装numpy和scipy?

任何想法将不胜感激.

当我做

echo $PYTHONPATH

我明白了

/usr/lib/python2.7/dist-packages

解决方法:

>它说你需要python 2.7(你已经拥有):

$python --version

Python 2.7.4

>然后它说你也需要numpy包,版本> = 1.4.1:

apt-cache policy python-numpy

python-numpy:

Installed: (none)

Candidate: 1:1.7.1-1ubuntu1

Version table:

1:1.7.1-1ubuntu1 0

500 http://archive.ubuntu.com/ubuntu/ raring/main amd64 Packages

如您所见,我有numpy版本1.7.1,所以让我们继续安装它:

sudo apt-get install python-numpy

>现在它说我们需要cython,让我们检查一下这个包是否可用:

apt-cache policy cython

cython:

Installed: (none)

Candidate: 0.17.4-0ubuntu1

Version table:

0.17.4-0ubuntu1 0

500 http://archive.ubuntu.com/ubuntu/ raring/main amd64 Packages

我们有它,我们安装它:

sudo apt-get install cython

请注意,还有其他正在安装的依赖包.

>奇怪的是,我们也需要scipy模块:

sudo apt-get install python-scipy

>测试.在终端中打开python并输入以下内容:

$python

Python 2.7.4 (default, Sep 26 2013, 03:20:26)

[GCC 4.7.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import numpy

>>> import scipy

>>> import cython

>>> exit()

以上,必须没有错误.如果出现问题,请再次阅读指南,忘记/滑了一步.

>从他们的页面下载CLASS源,转到终端中的目录,然后解压缩并创建它:

cd where/the/tar/is

tar zxf class_v2.0.2.tar.gz

cd class_v2.0.2

make

在这里,我们将等到完成.完成后,我们转到python目录并启动魔术.没有从目录移动运行:

cd python

python setup.py build

python setup.py install --user

现在我们在用户目录中安装了CLASS.我们应该测试一下!

python

Python 2.7.4 (default, Sep 26 2013, 03:20:26)

[GCC 4.7.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from classy import Class

>>> exit()

在这里,一切都很好.

>现在真相,在你的代码目录中下载monthypython tarball:

cd ~

mkdir code

cd code

wget https://www.dropbox.com/s/l7mnhwsktp1m8b5/montepython_v1.2.5.tar.bz2?dl=1 -O montepython_v1.2.5.tar.bz2

tar jxf montepython_v1.2.5.tar.bz2

在安装说明are some notes中,与此特殊情况(新安装)无关,但在更新montepython时可能很重要.

>这一变化很重要.你还记得你安装CLASS的地方吗?现在你应该告诉Monte Python在哪里.在我的情况下它是/home/braiam/src/class_v2.0.2/class,你的可能会有所不同.您可以使用find来查找它:

find ~ -name class -print

好吧,现在我使用你喜欢的任何东西修改default.conf文件(我将使用nano)并修改根路径,所以完整的文件将如下所示:

# Fill in the relevant path to your personal distribution.

# If you create a new file out of this one, please remember to call

# MontePython.py with the option '-conf my.conf'

# At minimum, this file should contain one line:

# ** path['cosmo'] = path to the cosmological code you are using. Note, if you are

# using a modified version of class, be sure that the path contains the word

# class, otherwise the code might not recognise it.

# If you want to use a data folder different from the one present in the folder

# you are executing the code, please also add:

# ** path['data'] = /path/to/the/other/data/

root = '/home/braiam/src/class_v2.0.2/'

path['cosmo'] = root+'/class/'

保存文件并退出.

>测试montepython!如果一切正常,你应该能够在你的montepythong目录中运行代码/ MontePython.py –help,并且一切都应该运行:

~/src/montepython$code/MontePython.py --help

usage: MontePython.py [-h] [-N number of steps] [-o output folder]

[-p input param file] [-c input cov matrix]

[-j jumping method] [-f jumping factor]

[-conf configuration file] [-chain_number chain number]

[-r restart from chain] [-bf restart from best fit file]

[-info [compute information of desired file [compute information of desired file ...]]]

[-bins desired number of bins, default is 20] [-no_mean]

[-comp comparison folder]

[-extra plot file for custom needs] [-noplot] [-all]

[-ext change extension for the output file]

[-fontsize desired fontsize, default is 15]

[-ticksize desired ticksize, default is 13]

Monte Python, a Monte Carlo code in Python

optional arguments:

-h, --help show this help message and exit

-N number of steps

-o output folder

-p input param file

-c input cov matrix

-j jumping method

-f jumping factor

-conf configuration file

-chain_number chain number

-r restart from chain

-bf restart from best fit file

-info [compute information of desired file [compute information of desired file ...]]

-bins desired number of bins, default is 20

-no_mean

-comp comparison folder

-extra plot file for custom needs

-noplot

-all

-ext change extension for the output file

-fontsize desired fontsize, default is 15

-ticksize desired ticksize, default is 13

有了这个,你已经安装了montepython并准备好了!

标签:python,software-installation

来源: https://codeday.me/bug/20190807/1609942.html

python安装numpy-如何为python安装numpy和scipy?相关推荐

  1. 使用eclipse安装python插件_如何为eclipse安装合适版本的python插件pydev

    pydev是一款优秀的Eclipse插件,大多数喜欢在eclipse开发软件的程序员(也许是java程序员)在开发python软件时希望继续使用eclipse,那么pydev是非常理想的选择. 1.安 ...

  2. python tkinter 安装_如何为Python安装tkinter?

    如果你和我一样,由于你在I.S中的好朋友而在你的网络上没有根目录特权,而且你是在本地安装中工作的,你可能会在上面的方法上遇到一些问题. 我在谷歌上花了很长时间--但最终,这很容易. 要在Linux上本 ...

  3. python webbrowser安装_如何为python webbrows设置BROWSER环境变量

    我正在尝试注册Firefox浏览器以在Windows上运行.根据Webbrowser的文档,"如果环境变量BROWSER存在,它被解释为覆盖浏览器的平台默认列表,作为操作系统路径-单独列出要 ...

  4. python卸载_如何为Python程序制作Windows安装包?

    我们使用Python可以编写很多提高工作和学习效率的小工具,在编写完之后,如果我们想将其分享给更多的人使用,那么最便捷的方法就是将其打包为可执行程序. 在Windows环境下,我们使用Pyinstal ...

  5. chocolatey 安装_如何为Windows安装和使用Chocolatey Package Manager?

    chocolatey 安装 Linux distributions have different package managers like apt, yum, dnf in order to ins ...

  6. python机器学习包 Windows下 pip安装 scikit-learn numpy scipy

    1.到PIP的目录中C:\Python34\Scripts;2. 2.1  pip安装numpy pip install numpy 2.2  pip安装sklearn pip install -U ...

  7. 为什么python安装不了numpy库_python 安装与numpy matplotlib 等库安装

    1.下载并安装Python3.4 在官网下载即可:Python官网 2.安装pip (1)查看是否已安装pip 进入cmd命令窗口,输入pip --version ,查看是否已安装pip,如果出现下图 ...

  8. python库下载安装报错_python3.6下Numpy库下载与安装图文教程

    今天在做Plotly的散点图时,需要Numpy 这个库的使用. 没有安装Numpy这个库的时候,报错一般是下图这样:ModuleNotFoundError: No module named 'nump ...

  9. python numpy安装教程_手把手教你搭建机器学习开发环境—Python与NumPy的超简安装教程...

    手把手教你搭建机器学习开发环境Python语言是机器学习的基础,所以,想要入门机器学习,配置好Python的开发环境是第一步.本文就手把手的教你配置好基于Python的机器学习开发环境.超简单!第一步 ...

最新文章

  1. Java实现pdf和Excel的生成及数据动态插入、导出
  2. 编译包含Google Play服务App的SDK版本问题
  3. 养胃记住“红黄绿白黑”
  4. 安全绳使用方法图解_电暖器的使用方法与安全注意事项
  5. 定时任务调度系统设计
  6. [填坑]SerialPort的“端口被关闭”
  7. 計算機二級-java07
  8. 算法学习三:使用霍纳规则计算多项式
  9. CoreJava Reading Note(3:Fundamental structure)
  10. 离散数学:幂集,生成
  11. Python语言特色集锦
  12. Hibernate:DisjunctionConjunction构造复杂的查询条件.
  13. 各种符号用英语怎么念
  14. 数据挖掘之对河南省的疫情分析
  15. torch.bmm()函数解读
  16. 4、spss做多元线性回归
  17. 虎牙点选/虎牙滑块本地识别DLL
  18. 联合搜索:搜索中的所有需求
  19. 亚米社区app v1.1.6
  20. gym 100543 CERC 2014 L Outer space invaders

热门文章

  1. java-2018-01-17计划
  2. 生产者/消费者问题的多种Java实现方式
  3. JAVA Thread线程异常监控
  4. cocos2d-x CCParticleSystem粒子系统
  5. Objective-C语法之代码块(block)的使用
  6. BootStrap入门教程 (四)
  7. python基础知识选择题-99道经典练习题助你全面掌握python基础知识,附技巧答案...
  8. python自带的集成开发环境是什么-Python的10大集成开发环境和代码编辑器(指南)...
  9. python程序设计报告-Python程序设计实验一报告
  10. python开发微信小程序-微信小程序开发:python+sanic 实现小程序登录注册