python 3.74 运行import numpy as np 报错lib\site-packages\numpy\__init__.py

yipeiwu_com6年前Python基础

安装完 anaconda

运行如下代码执行不了

import numpy as np
import os,sys

#获取当前文件夹,并根据文件名
def path(fileName):
 p=sys.path[0]+'\\'+fileName
 return p

#读文件 
def readFile(fileName):
 f=open(path(fileName))
 str=f.read()
 f.close()
 return str
 
#写文件 
def writeFile(fileName,str):
 f=open(path(fileName),'w')
 f.write(str)
 f.close()

def str1():
 str=','.join('我在中国大地上骄傲地生长着!')
 return str

def str2():
 return str(np.random.randint(-49,50,[3,3,3]))

#实验1 
def test_1():
 fileName='中国大地.txt'
 writeFile(fileName,str1())
 list=readFile(fileName).split(',')
 print(list)

#实验2
def test_2():
 writeFile('str1',str1())
 writeFile('str2',str2())
 str_1=readFile('str1')
 str_2=readFile('str2')
 print(str_1)
 print(str_2)
 
test_2()

提示如下错误

Traceback (most recent call last):
  File "F:\python\testfile.py", line 1, in <module>
    import numpy as np
  File "d:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140,
 in <module>
    from . import _distributor_init
  File "d:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py",
line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: 找不到指定的模块。

或者如下错误

python3.7 -u "/Users/fukai/fk-test-python/l02/main.py"
控制台报错
Traceback (most recent call last):
File "/Users/fukai/fk-test-python/l02/main.py", line 1, in <module>
import numpy as np

问题
1. anaconda 环境怎么解决这个问题呢

答案:经过【听图阁-专注于Python设计】小编的测试发现其实只要更新numpy模块就可以了,可以通过如下两种方式

conda update numpypip install -U numpy都可以实现更新。

更新以后,再执行就正常了。

pip -i 和 -U 参数

例子:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -U funcat

-i: 指定库的安装源

-U:升级 原来已经安装的包,不带U不会装新版本,带上U才会更新到最新版本。

anaconda用法:

查看已经安装的包:
pip list 或者 conda list

安装和更新:

pip install requests
pip install requests --upgrade

或者

conda install requests
conda update requests

更新所有库

conda update --all

更新 conda 自身

conda update conda

更新 anaconda 自身

conda update anaconda

anaconda换源:

制定清华的源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
有资源显示源地址:
conda config --set show_channel_urls yes

相关文章

Python引用传值概念与用法实例小结

本文实例讲述了Python引用传值概念与用法。分享给大家供大家参考,具体如下: Python函数的参数传值使用的是引用传值,也就是说传的是参数的内存地址值,因此在函数中改变参数的值,函数...

使用python和pygame绘制繁花曲线的方法

使用python和pygame绘制繁花曲线的方法

前段时间看了一期《最强大脑》,里面各种繁花曲线组合成了非常美丽的图形,一时心血来潮,想尝试自己用代码绘制繁花曲线,想怎么组合就怎么组合。 真实的繁花曲线使用一种称为繁花曲线规的小玩意绘制...

python实现从字典中删除元素的方法

本文实例讲述了python实现从字典中删除元素的方法。分享给大家供大家参考。具体分析如下: python的字典可以通过del方法进行元素删除,下面的代码详细演示了这一过程 # Cre...

Python的Django框架中的表单处理示例

组建一个关于书籍、作者、出版社的例子: from django.db import models class Publisher(models.Model): name = m...

python对list中的每个元素进行某种操作的方法

如下所示: ''' 对列表中的每个元素进行某种操作 ''' def add(c): return c**2 l = [1,2,3] d1 = map(add,l) print d...