经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » NumPy » 查看文章
python 3.74 运行import numpy as np 报错lib\site-packages\numpy\__init__.py
来源:jb51  时间:2019/10/8 9:03:08  对本文有异议

安装完 anaconda

运行如下代码执行不了

  1. import numpy as np
  2. import os,sys
  3.  
  4. #获取当前文件夹,并根据文件名
  5. def path(fileName):
  6. p=sys.path[0]+'\\'+fileName
  7. return p
  8.  
  9. #读文件
  10. def readFile(fileName):
  11. f=open(path(fileName))
  12. str=f.read()
  13. f.close()
  14. return str
  15. #写文件
  16. def writeFile(fileName,str):
  17. f=open(path(fileName),'w')
  18. f.write(str)
  19. f.close()
  20.  
  21. def str1():
  22. str=','.join('我在中国大地上骄傲地生长着!')
  23. return str
  24.  
  25. def str2():
  26. return str(np.random.randint(-49,50,[3,3,3]))
  27.  
  28. #实验1
  29. def test_1():
  30. fileName='中国大地.txt'
  31. writeFile(fileName,str1())
  32. list=readFile(fileName).split(',')
  33. print(list)
  34.  
  35. #实验2
  36. def test_2():
  37. writeFile('str1',str1())
  38. writeFile('str2',str2())
  39. str_1=readFile('str1')
  40. str_2=readFile('str2')
  41. print(str_1)
  42. print(str_2)
  43. 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 环境怎么解决这个问题呢

答案:经过w3xue小编的测试发现其实只要更新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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号