我想在Ubuntu上安装Python和SQLAlchemy.这是我的命令:
sudo easy_install sqlalchemy
Run Code Online (Sandbox Code Playgroud)
但它失败了,我该怎么办?
我知道scrapy应首先安装w3lib,所以我先安装w3lib,但是当我在python ide中导入scrapy时,程序崩溃了.错误:
creating Twisted.egg-info
writing requirements to Twisted.egg-info\requires.txt
writing Twisted.egg-info\PKG-INFO
writing top-level names to Twisted.egg-info\top_level.txt
writing dependency_links to Twisted.egg-info\dependency_links.txt
writing manifest file 'Twisted.egg-info\SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'Twisted.egg-info\SOURCES.txt'
writing manifest file 'Twisted.egg-info\SOURCES.txt'
copying twisted\internet\_sigchld.c -> build\lib.win-amd64-2.7\twisted\internet
creating build\lib.win-amd64-2.7\twisted\internet\iocpreactor\iocpsupport
copying twisted\internet/iocpreactor/iocpsupport\iocpsupport.c -> build\lib.win-amd64-2.7\twisted\internet/iocpreactor/i
ocpsupport
copying twisted\internet/iocpreactor/iocpsupport\winsock_pointers.c -> build\lib.win-amd64-2.7\twisted\internet/iocpreac
tor/iocpsupport
copying twisted\python\_epoll.c -> build\lib.win-amd64-2.7\twisted\python
copying twisted\python\_initgroups.c -> build\lib.win-amd64-2.7\twisted\python
copying twisted\python\sendmsg.c -> build\lib.win-amd64-2.7\twisted\python
copying twisted\runner\portmap.c -> build\lib.win-amd64-2.7\twisted\runner
copying twisted\test\raiser.c -> build\lib.win-amd64-2.7\twisted\test
running build_ext
Run Code Online (Sandbox Code Playgroud)
怎么了?
我用c写了一个python扩展。
我使用c程序来加密一个字符串。
我的c程序:
#include <Python.h>
static const char *codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const unsigned char map[256] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255,
255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
255, 254, …Run Code Online (Sandbox Code Playgroud) Python版本:3.5.2
我的代码:
a = b"\xff"
b = a.replace(b"f", b"d")
print(b)
Run Code Online (Sandbox Code Playgroud)
我有b'\xff'。我尝试了另一种方法。首先,我将字节转换为str,然后替换字符串。
a = b"\xff"
b = a.decode()
b = b.replace("f", "d")
Run Code Online (Sandbox Code Playgroud)
但通过例外:
Traceback (most recent call last):
File "<input>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决 python3 中的问题。我应该怎么办?
我想编写一个返回字符串而不是字节的函数。
功能:
def read_image(path):
with open(path, "rb") as f:
data = f.read()
return data
image_data = read_image("/home/user/icon.jpg")
Run Code Online (Sandbox Code Playgroud)
如何将值转换image_data为类型str。如果成功转换为字符串,如何将字符串转换为字节。