2017-05-19 6 views
3

pip3 install slugify을 사용하여 설치 한 slugify을 사용하려고합니다. 그러나, 인터프리터, 나는 다음을 참조 문자열 'hello' slugify하려고하면 : 파이썬 2 대조적으로파이썬 3에서 slugify를 사용하는 방법은 무엇입니까?

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
Type "copyright", "credits" or "license" for more information. 

IPython 5.1.0 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: from slugify import slugify 

In [2]: slugify('hello') 
--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
<ipython-input-2-a58110f37579> in <module>() 
----> 1 slugify('hello') 

/usr/local/lib/python3.5/dist-packages/slugify.py in slugify(string) 
    22 
    23  return re.sub(r'[-\s]+', '-', 
---> 24    unicode(
    25     re.sub(r'[^\w\s-]', '', 
    26      unicodedata.normalize('NFKD', string) 

NameError: name 'unicode' is not defined 

In [3]: slugify(u'hello') 
--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
<ipython-input-3-acc9f7b8d41e> in <module>() 
----> 1 slugify(u'hello') 

/usr/local/lib/python3.5/dist-packages/slugify.py in slugify(string) 
    22 
    23  return re.sub(r'[-\s]+', '-', 
---> 24    unicode(
    25     re.sub(r'[^\w\s-]', '', 
    26      unicodedata.normalize('NFKD', string) 

NameError: name 'unicode' is not defined 

을, 후자는 수행 업무 : 나는이 얻을 수있는 방법

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
Type "copyright", "credits" or "license" for more information. 

IPython 2.4.1 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: from slugify import slugify 

In [2]: slugify(u'hello') 
Out[2]: u'hello' 

파이썬 3에서 작동합니까?

답변

8

slugify package you installed은 파이썬 3 용으로 제작되지 않았지만 현재는 파이썬 2 만 지원합니다. 그리고 업데이트 될 가능성은 희박합니다. 말할 수있는 가장 쉬운 방법 중 하나는 소스 코드를 통해, 그것은하는이 파이썬에 존재하지 않는 파이썬이 키워드 unicode을 사용한다는 것입니다 3.

당신은 아마 않았다

pip install slugify 

이었다 있다는 구식 패키지가 아니라 연결된 패키지.

링크 된 slugify 패키지를 설치하려면 https://pypi.python.org/pypi/python-slugify, 설치시 python-slugify이라고 불리우며 최근의 모든 Python 버전을 지원합니다. 그리고 더 많은 기능을 보유하십시오.

pip install python-slugify 

그리고 다른 패키지와 같은 방법으로 가져옵니다

from slugify import slugify 

참고 : 가 같은 이름을 사용하기 때문에 당신이, 당신이 설치 원본 패키지를 삭제해야합니다.