失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python安装numpy-如何为python安装numpy和scipy?

python安装numpy-如何为python安装numpy和scipy?

时间:2024-02-26 03:07:51

相关推荐

python安装numpy-如何为python安装numpy和scipy?

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

(我有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_setup.py -O- | python”sudo sh -c“wget /pypa/pip/master/contrib/ get-pip.py -O- | python“然后使用pip安装它们,如(4)中所示

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

http://python-/distribute_setup.py

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

wget: unable to resolve host address `python-'

>我还尝试从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 /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 /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 , 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 , 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 /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/0807/1609942.html

如果觉得《python安装numpy-如何为python安装numpy和scipy?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。