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模块hashlib(加密服务)知识点讲解

官方文案:https://docs.python.org/zh-cn/3/library/hashlib.html hashlib --- 安全哈希与消息摘要 Python的hashl...

python 将大文件切分为多个小文件的实例

切分文件 最近遇到需要切分文件的需求,当然首选用python来解决,网上搜了下感觉都太复杂了,其实用python自带函数即可解决。 f = open('path&filename',...

Python判断一个list中是否包含另一个list全部元素的方法分析

本文实例讲述了Python判断一个list中是否包含另一个list全部元素的方法。分享给大家供大家参考,具体如下: 你可以用for in循环+in来判断 #!/usr/bin/env...

python pandas 组内排序、单组排序、标号的实例

python pandas 组内排序、单组排序、标号的实例

摘要:本文主要是讲解一下,如何进行排序。分为两种情况,不分组进行排序和组内进行排序。什么意思呢?具体来说,我举个栗子。 ****注意**** 如果只是单纯想对某一列进行排序,而不进行打序...

pyttsx3实现中文文字转语音的方法

如下所示: import pyttsx3 import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer,...