系统:OX E. Python源码:python.org
我用pip来安装matplotlib,这是我得到的结果
sudo pip install matplotlib
目录' / Users / clarence / Library / Caches / pip / http'或其父母 目录不归当前用户所有,并且缓存已经存在 禁用。请检查该目录的权限和所有者。如果 用sudo执行pip,你可能想要sudo' s -H标志。目录 ' /用户/克拉伦斯/库/缓存/ PIP'或其父目录不是 由当前用户拥有并且缓存轮已被禁用。校验 该目录的权限和所有者。如果执行pip sudo,你可能想要sudo的-H标志。要求已经满足(使用 - 升级升级):/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python中的matplotlib 要求已经满足(使用--upgrade升级):numpy> = 1.5 在 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):龙卷风在/Library/Python/2.7/site-packages(来自 matplotlib)要求已经满足(使用--upgrade升级): pyparsing> = 1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):鼻子在/Library/Python/2.7/site-packages(来自matplotlib) 要求已经满足(使用--upgrade升级):certifi in /Library/Python/2.7/site-packages(来自tornado-> matplotlib) 要求已经满足(使用--upgrade升级): backports-abc> = 0.4 in /Library/Python/2.7/site-packages(来自 tornado-> matplotlib)要求已经满足(使用--upgrade to 升级):backports.ssl-match-hostname in /Library/Python/2.7/site-packages(来自tornado-> matplotlib) 要求已经满足(使用--upgrade升级): singledispatch in /Library/Python/2.7/site-packages(来自 tornado-> matplotlib)要求已经满足(使用--upgrade to 升级):六进 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自singledispatch-> tornado-> matplotlib)Clarences-MacBook-Pro:〜 clarence $ sudo -H pip install matplotlib已经要求了 满意(使用--upgrade升级):matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python 要求已经满足(使用--upgrade升级):numpy> = 1.5 在 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):龙卷风在/Library/Python/2.7/site-packages(来自 matplotlib)要求已经满足(使用--upgrade升级): pyparsing> = 1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自matplotlib)要求已经满足(使用--upgrade to 升级):鼻子在/Library/Python/2.7/site-packages(来自matplotlib) 要求已经满足(使用--upgrade升级):certifi in /Library/Python/2.7/site-packages(来自tornado-> matplotlib) 要求已经满足(使用--upgrade升级): backports-abc> = 0.4 in /Library/Python/2.7/site-packages(来自 tornado-> matplotlib)要求已经满足(使用--upgrade to 升级):backports.ssl-match-hostname in /Library/Python/2.7/site-packages(来自tornado-> matplotlib) 要求已经满足(使用--upgrade升级): singledispatch in /Library/Python/2.7/site-packages(来自 tornado-> matplotlib)要求已经满足(使用--upgrade to 升级):六进 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (来自singledispatch-> tornado-> matplotlib)
当我继续在python中导入该库时。 python说它无法找到模数。
python3.5 -c 'import matplotlib; print(matplotlib.__version__, matplotlib.__file__)'
回溯(最近一次呼叫最后一次):文件"",第1行,in ImportError:没有名为' matplotlib'
的模块
我该如何解决这个问题?
答案 0 :(得分:0)
您需要为以后要用于执行代码的同一版本的python安装这些库。
因此,如果要使用Python 2.7,则必须调用
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define PORT 4444
int main(){
int sockfd, ret;
struct sockaddr_in serverAddr; // Local address
int newSocket;
struct sockaddr_in newAddr;
socklen_t addr_size;
char buffer[1024];
pid_t childpid;
// Create socket for incoming connections
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0){
printf("Error in connection.\n");
exit(1);
}
printf("Server Socket is created.\n");
// Construct local address structure
memset(&serverAddr, '\0', sizeof(serverAddr)); // Zero out structure
serverAddr.sin_family = AF_INET; // IPv4 address family
serverAddr.sin_port = htons(PORT); // Local port
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
// Bind to the local address
ret = bind(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if(ret < 0){
printf("Error in binding.\n");
exit(1);
}
printf("Bind to port %d\n", 4444);
// Mark the socket so it will listen for incoming connections
if(listen(sockfd, 10) == 0){ //Maximum outstanding connection requests is 10
printf("Listening....\n");
}else{
printf("Error in binding.\n");
}
while(1){
// Wait for clients to connect
newSocket = accept(sockfd, (struct sockaddr*)&newAddr, &addr_size);
if(newSocket < 0){
exit(1);
}
// newSocket is connected to client!
char newName[INET_ADDRSTRLEN]; // String to contain client address
if (inet_ntop(AF_INET, &newAddr.sin_addr.s_addr, newName, sizeof(newName)) != NULL)
printf("Handling client %s/ %d\n", newName, ntohs(newAddr.sin_port));
else
printf("Unable to get client address");
//Handle concurrency by using fork
if((childpid = fork()) == 0){
close(sockfd);
while(1){
recv(newSocket, buffer, 1024, 0);
int i=0;
char *array[20];
char **reply = malloc(20*sizeof(char *));
char *p = strtok(buffer, ",");
while (p!=NULL) {
array[i++] = p;
p = strtok(NULL, ","); //stroke received string into tokens
}
for (i=0; i<20; i++) {
reply[i] = malloc(10*sizeof(char));
strcpy(reply[i], array[i]); //input tokens into array
printf("%s ", reply[i]);
}
send(newSocket, reply, 20*sizeof(char *), 0);
bzero(reply, sizeof(reply));
//}
}
}
}
close(newSocket);
return 0;
}
使用python 3.5时,请以类似方式使用
sudo pip2 install matplotlib