我试图使用matplotlib绘制一些数据.导入库时,我收到错误:
ImportError: matplotlib requires pyparsing
Run Code Online (Sandbox Code Playgroud)
我安装了pyparsing easy_install pyparsing,但错误不断出现.
我怎么解决这个问题?或者,有没有替代matplotlib来绘制Python的东西?
编辑: sys.path返回:
['', 'C:\\Python27\\lib\\site-packages\\spyderlib\\utils\\external', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\Python27\\lib\\site-packages\\IPython\\extensions']
Run Code Online (Sandbox Code Playgroud)
尝试导入pyparsing会返回错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Python27/Lib/site-packages/xy/simulation.py", line 4, in <module>
import pyparsing
ImportError: No module named pyparsing
Run Code Online (Sandbox Code Playgroud) 我正在尝试定义一个将字符串作为键和任何值的字典。因此,我尝试使用Dict{String, <:Any}as 类型。但是,该表达式的返回值是
> Dict{String,#s27} where #s27
Run Code Online (Sandbox Code Playgroud)
此外,如果我尝试定义该类型的字典,则会出现错误:
Dict{String,<:Any}()我得到ERROR: MethodError: no method matching Dict{String,#s28} where #s28()Dict{String,<:Any}("aa"=>42)我得到ERROR: MethodError: no method matching Dict{String,#s29} where #s29(::Pair{String,Int64})我也尝试使用Dict{String}(应该是等效的),结果相似。
我在这里缺少什么类型的字典?
我想使用itertools.product或类似的命令来获取n迭代器副本iter与自身的笛卡尔积,其中n是一个变量。我尝试通过递归构建它
import itertools
prod_iter = iter
for i in xrange(n-1):
prod_iter = itertools.product(prod_iter,iter)
Run Code Online (Sandbox Code Playgroud)
但是从,比如说,开始iter=xrange(2),n=3然后运行
for i in prod_iter:
print i
Run Code Online (Sandbox Code Playgroud)
我得到作为输出
((0,0),0)
((0,0),1)
((0,1),0)
...
Run Code Online (Sandbox Code Playgroud)
并不是
(0,0,0)
(0,0,1)
(0,1,0)
...
Run Code Online (Sandbox Code Playgroud)
如我所愿。有没有办法做到这一点?
我已经编写了以下python函数:
import numpy
def primes_iterable():
"""Iterable giving the primes"""
# The lowest primes
primes = [2,3,5]
for p in primes:
yield p
for n in potential_primes():
m = int(numpy.sqrt(n))
check = True
for p in primes:
if p > m:
break
if n%p == 0:
check = False
if check:
primes.append(n)
yield n
def potential_primes():
"""Iterable starting at 7 and giving back the non-multiples of 2,3,5"""
yield 7
n = 7
gaps = [4,2,4,2,4,6,2,6]
while 1:
for g in gaps: …Run Code Online (Sandbox Code Playgroud)