1. 程式人生 > 程式設計 >詳解python模組pychartdir安裝及匯入問題

詳解python模組pychartdir安裝及匯入問題

在遷移別人寫好的指令碼時,發現pychartdir沒有匯入,指令碼執行報錯。以下是報錯內容:

[modps@LGJF-ZYC5-MMSC-WEB02 ~]$ python /opt/aspire/product/modps/mopps/shell/dayreport_linux.py
/etc/host.conf: line 1: bad command `nospoof on'
Traceback (most recent call last):
 File "/opt/aspire/product/modps/mopps/shell/dayreport_linux.py",line 42,in <module>
 from pychartdir import *
ImportError: No module named pychartdir

之前使用的是pip來安裝模組的,先安裝下pip:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py

然後開始下載pychartdir模組:

[root@LGJF-ZYC5-MMSC-WEB02 ~]# pip install pychartdir
DEPRECATION: Python 2.7 reached the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
/etc/host.conf: line 1: bad command `nospoof on'
ERROR: Could not find a version that satisfies the requirement pychartdir (from versions: none)
ERROR: No matching distribution found for pychartdir

發現報錯了,報錯的大概意思為:未找到合適的版本。

那麼就只好手動安裝了

1.從官方地址下載python版本的ChartDirector並解壓

https://www.advsofteng.com/download.html

# 使用lrzsz命令將下載的包傳遞到伺服器上
[root@LGJF-ZYC5-MMSC-WEB02 ~]# tar -xf chartdir_python_linux_64.tar.gz

2.在python模組安裝目錄下(/usr/lib/python2.7/site-packages)建立一個chartdirector的目錄

# 檢視模組安裝目錄
[root@LGJF-ZYC5-MMSC-WEB02 ~]# python
Python 2.7.5 (default,May 3 2017,07:55:04) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['','/usr/lib64/python27.zip','/usr/lib64/python2.7','/usr/lib64/python2.7/plat-linux2','/usr/lib64/python2.7/lib-tk','/usr/lib64/python2.7/lib-old','/usr/lib64/python2.7/lib-dynload','/usr/lib64/python2.7/site-packages','/usr/lib64/python2.7/site-packages/gtk-2.0','/usr/lib/python2.7/site-packages']
>>> 
[root@LGJF-ZYC5-MMSC-WEB02 ~]# cd /usr/lib/python2.7/site-packages
[root@LGJF-ZYC5-MMSC-WEB02 site-packages]# mkdir chartdirector
[root@LGJF-ZYC5-MMSC-WEB02 site-packages]# cd chartdirector
[root@LGJF-ZYC5-MMSC-WEB02 chartdirector]# pwd
/usr/lib/python2.7/site-packages/chartdirector

3.進入解壓好的Chartdirector/ lib,將其下面的內容拷貝到上邊建立的目錄下,同時在site-packages下建立一個chartdirector.pth,寫入chartdirector到檔案中:

[root@LGJF-ZYC5-MMSC-WEB02 chartdirector]# cd
[root@LGJF-ZYC5-MMSC-WEB02 ~]# cd ChartDirector/lib/
[root@LGJF-ZYC5-MMSC-WEB02 lib]# cp -a ./* /usr/lib/python2.7/site-packages/chartdirector/
[root@LGJF-ZYC5-MMSC-WEB02 lib]# cd /usr/lib/python2.7/site-packages/
[root@LGJF-ZYC5-MMSC-WEB02 site-packages]# cat chartdirector.pth
chartdirector

4.開啟python IDE,匯入該模組試試:

[root@LGJF-ZYC5-MMSC-WEB02 site-packages]# python
Python 2.7.5 (default,"credits" or "license" for more information.
>>> import pychartdir

5.執行指令碼,執行成功!

到此這篇關於python模組pychartdir匯入問題的文章就介紹到這了,更多相關python模組pychartdir內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!