我无法在我的Mac上安装一个名为PyEnchant的Python模块.我使用的是Python 2.7.当我打开并运行pyenchant setup.py文件时,我收到以下错误消息:
Traceback (most recent call last):
File "/Applications/Python 2.7/pyenchant-1.6.5/setup.py", line 195, in <module>
import enchant
File "/Applications/Python 2.7/pyenchant-1.6.5/enchant/__init__.py", line 90, in <module>
from enchant import _enchant as _e
File "/Applications/Python 2.7/pyenchant-1.6.5/enchant/_enchant.py", line 133, in <module>
raise ImportError("enchant C library not found")
ImportError: enchant C library not found
Run Code Online (Sandbox Code Playgroud)
我已经尝试运行pyenchant网站上提供的.dmg文件.安装过程没有任何错误消息,但是一旦完成,我仍然无法将pyenchant导入Python,也无法在Finder中的任何位置找到已安装的软件.
我还尝试使用.egg安装程序,它打开了一个Python窗口,其中黑色大写字母顶部写着字母"PK".我不知道这意味着什么.
您可能会告诉我,我不是一位经验丰富的Python用户,所以对此有任何帮助都非常感谢.
我想问一下 web2py 和 django 用户使用哪些工具/模块来扫描用户上传的文件中是否存在恶意软件、病毒等。您能否根据您的个人经验提供一些建议?谢谢。
我是Python C-API和模块创建的新手.我试图创建一个c-hash python模块.我使用python 3.4.3和TDM-gcc(64bit)4.9.2进行Windows上的编译.
这是我的代码:
// hash_mod.c
#include <Python.h>
unsigned long _hash(unsigned char const* str)
{
unsigned long hash = 5381;
int c;
int i;
i = 0;
while (str[i] != '\0')
{
c = str[i];
hash = ((hash << 5) + hash) + c;
++i;
}
return hash;
}
static PyObject*
hash_hash(PyObject* self, PyObject* args)
{
unsigned char const* str;
if (!PyArg_ParseTuple(args, "s", &str))
return NULL;
return PyLong_FromUnsignedLong(_hash(str));
}
static PyMethodDef HashMethods[] = {
{"hash", hash_hash, METH_VARARGS, "String Hash"}, …Run Code Online (Sandbox Code Playgroud) 我mytest.py在工作目录中有一个文件,内容如下:
class MyTest(object):
def __init__(self):
print(1)
pass
Run Code Online (Sandbox Code Playgroud)
在jupyter我有这些细胞。
单元格1:
%reload_ext autoreload
%autoreload 2
import mytest
Run Code Online (Sandbox Code Playgroud)
单元格2:
x = mytest.MyTest()
Run Code Online (Sandbox Code Playgroud)
如果我从一个新的内核开始,那么它将按预期工作,并且给了我1。现在,如果我进入mytest.py将打印输出更改为2并重新运行Cell 2,我将得到:
1
[autoreload of mytest failed: Traceback (most recent call last):
File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
]
[autoreload of mytest failed: Traceback (most recent call last):
File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
] …Run Code Online (Sandbox Code Playgroud) 我正在尝试导入我在python中编写的模块,该模块只打印出包含数字的列表.我遇到的问题是我希望能够从一个单独的目录中导入它,但到目前为止我读过的答案似乎并不适用于我的情况.
例如,鉴于我想从我的文档文件夹中的目录导入printnumbers.py,我应该实现以下内容:
import sys
sys.path.append('/home/jake/Documents')
import printnumbers.py
Run Code Online (Sandbox Code Playgroud)
这段代码导致"导入错误",告诉我指定的模块不存在.我不确定从哪里开始,我已多次检查以确保它是路径和模块名称的正确拼写.我仍然试图准确理解附加到"sys.path"的内容.根据我的理解,它告诉程序在该目录中搜索模块?
感谢任何回答我的新手问题的人.我只是想更好地理解python文档不能提供我的思维框架.
在过去的几个小时中,我一直在使用Google搜索,在任何地方都找不到等效的问题。此外,2.7和3.5的文档似乎相同,因此我认为没有记录这种行为。
这是我的目录结构:
project
-- project.py
-- api
-- __init__.py
-- subapi
-- __init__.py
Run Code Online (Sandbox Code Playgroud)
的内容project/project.py:import api
的内容project/api/__init__.py:import subapi
如果我python project.py从projects文件夹中执行(使用python 2.7),它将返回而不会出现错误。如果我对python 3(python3 project.py)执行相同操作,则崩溃
Traceback (most recent call last):
File "project.py", line 1, in <module>
import api
File "/home/me/Documents/project/api/__init__.py", line 1, in <module>
import subapi
ImportError: No module named 'subapi'
Run Code Online (Sandbox Code Playgroud)
如果我重写import语句以使用相对于项目目录(import api.subapi)的路径,则它适用于python 2和3。虽然这不是令人满意的解决方案,因为这要求我从子模块中引用父模块,这会导致失败。模块化的思想
有谁知道我该怎么做才能恢复python2的行为?模块搜索算法应优先使用import语句在文件的本地目录中搜索。顺便说一句,它还应优先考虑上述内置模块中的这些文件。尝试导入模块“测试”。
-编辑-stackoverflow要求我将我的问题与另一个称为“如何进行相对进口”的问题区分开。我认为这个问题有所不同,因为我专门询问两个版本之间的差异。使用相对导入是解决方案,而不是问题。
我有一个reqs.txt文件,包含我需要在第二台计算机上安装的许多python要求.该文件如下所示:
alabaster==0.7.9
anaconda-client==1.6.0
anaconda-navigator==1.4.3
astroid==1.4.9
astropy==1.3
Babel==2.3.4
backports.shutil-get-terminal-size==1.0.0
beautifulsoup4==4.5.3
bitarray==0.8.1
blaze==0.10.1
...
Run Code Online (Sandbox Code Playgroud)
我在用
pip3 install -r reqs.txt --requirement=reqs.txt
Run Code Online (Sandbox Code Playgroud)
我明白了
me@pc:~$ pip3 install -r reqs.txt --requirement=reqs.txt
Collecting alabaster==0.7.9 (from -r reqs.txt (line 1))
Using cached alabaster-0.7.9-py2.py3-none-any.whl
Collecting anaconda-client==1.6.0 (from -r reqs.txt (line 2))
Could not find a version that satisfies the requirement anaconda-client==1.6.0 (from -r reqs.txt (line 2)) (from versions: 1.1.1, 1.2.2)
No matching distribution found for anaconda-client==1.6.0 (from -r reqs.txt (line 2))
Run Code Online (Sandbox Code Playgroud)
对于该reqs.txt文件中的每个包.有任何想法吗?
编辑:reqs.txt文件是用pip freeze.创建的.即使我删除了版本号,它们仍然无法安装.但是,如果我做了一个
pip3 install alabaster …Run Code Online (Sandbox Code Playgroud) 我正在努力解决嵌套__init__.py在我正在编写的Python包中的问题。该包具有以下架构:
module/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 submodule1\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 source.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 submodule2\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 source.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 subsubmodule2\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 source.py\nRun Code Online (Sandbox Code Playgroud)\n我的目的是能够访问submodule2/source.pythroughmodule.submodule2.function和 in subsubmodules2/source.pythrough中定义的函数module.submodule2.subsubmodule2.function。
我尝试的第一件事就是__init__.py这样定义submodule2:
from .subsubmodule2 import *\nRun Code Online (Sandbox Code Playgroud)\nsubsubmodules2/source.py但这样做,我得到了through module.submodule2.function(and )中定义的函数module.function。
如果我做:
\nfrom . import subsubmodule2\nRun Code Online (Sandbox Code Playgroud)\n我通过module.subsubmodule2.function.
我还尝试__all__在 中定义关键字__init__,但没有成功。如果我很好地理解Python 文档,我想我可以保留空__init__.py文件并且它可以工作,但根据我的理解,这也不是最佳实践。
按照我的模块的预期访问这些功能的最佳方式是什么?
\n我有一个类FileSet有方法_process_series,它包含了一堆if-elif做块filetag的不同特异性格式pandas.Series:
elif filetag == "EntityA":
ps[filetag+"_Id"] = str(ps[filetag+"_Id"]).strip()
ps[filetag+"_DateOfBirth"] = str(pd.to_datetime(ps[filetag+"_DateOfBirth"]).strftime('%Y-%m-%d')).strip()
ps[filetag+"_FirstName"] = str(ps[filetag+"_FirstName"]).strip().capitalize()
ps[filetag+"_LastName"] = str(ps[filetag+"_LastName"]).strip().capitalize()
ps[filetag+"_Age"] = relativedelta(datetime.today(), datetime.strptime(ps[filetag+"_DateOfBirth"], "%Y-%m-%d")).years
return ps
Run Code Online (Sandbox Code Playgroud)
我想在类中定义一个抽象format方法,并将这些格式块保存在单独的模块中,这些模块在_process_series为给定的filetag. 原谅伪代码,但类似于:
for tag in filetag:
from my_formatters import tag+'_formatter' as fmt
ps = self.format(pandas_series, fmt)
return ps
Run Code Online (Sandbox Code Playgroud)
该模块将包含格式化块:
# my_formatters.EntityA_formatter
ps[filetag+"_Id"] = str(ps[filetag+"_Id"]).strip()
ps[filetag+"_DateOfBirth"] = str(pd.to_datetime(ps[filetag+"_DateOfBirth"]).strftime('%Y-%m-%d')).strip()
ps[filetag+"_FirstName"] = str(ps[filetag+"_FirstName"]).strip().capitalize()
ps[filetag+"_LastName"] = str(ps[filetag+"_LastName"]).strip().capitalize()
ps[filetag+"_Age"] = relativedelta(datetime.today(), datetime.strptime(ps[filetag+"_DateOfBirth"], "%Y-%m-%d")).years …Run Code Online (Sandbox Code Playgroud) 我已经尝试了下面给出的所有可能的命令:
pip 安装 pgi 、 pip 安装 PyGObject 、 pip 安装 python-gi
仍然无法在 python 中安装该模块。安装了python 3.7也尝试制作虚拟环境但无法安装模块。
#import cv2
import gi
import numpy as np
gi.require_version('Gst', '1.0')
from gi.repository import Gst
Run Code Online (Sandbox Code Playgroud) python-module ×10
python ×8
python-3.x ×3
c ×1
django ×1
format ×1
gstreamer ×1
import ×1
installation ×1
ipython ×1
jupyter ×1
methods ×1
module ×1
pandas ×1
pip ×1
pyenchant ×1
python-2.7 ×1
python-3.5 ×1
web2py ×1