sqlalchemy安装以及使用_CentOS7.3中无法直接通过pip3命令安装程序以及ipython3无法正常使用解决办法...

7a051413db10806959d6993af2b86c2a.png

一、问题现象

1、通过pip -V查看版本

[root@localhost bin]# pip -V

显示如下:

(python 2.7

显示如下:

bash: /usr/bin/pip3: /usr/bin/python3: 坏的解释器: 没有那个文件或目录

在python3的安装目录/usr/local/python3/bin下用./pip3 -V命令查看版本:

[root@localhost bin]# ./pip3 -V

显示如下:

pip 20.1.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)

无法直接通过pip3 -V查看其版本,属于软链接的问题,解决过程如下:

[root@localhost bin]# pip3 -V
bash: /usr/bin/pip3: /usr/bin/python3: 坏的解释器: 没有那个文件或目录
[root@localhost bin]# pip -V
pip 20.2b1 from /usr/lib/python2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
[root@localhost bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3ln: 无法创建符号链接"/usr/bin/pip3": 文件已存在
[root@localhost bin]# rm /usr/bin/pip3
rm:是否删除普通文件 "/usr/bin/pip3"?y
[root@localhost bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@localhost bin]# pip3 -V
pip 20.1.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)

2、通过ipython -V查看版本

[root@localhost bin]# ipython -V
3.2.1

在python3的安装目录/usr/local/python3/bin下用./ipython -V和./ipython3 -V查看,均返回如下异常:

Traceback (most recent call last):
File "./ipython3", line 5, in <module> from IPython import start_ipython ModuleNotFoundError: No module named 'IPython'

二、尝试解决

在/usr/local/python3/bin目录重新使用./pip3 install ipython安装:

[root@localhost bin]# ./pip3 install ipython
Requirement already satisfied: ipython in usr/local/python3/lib/python3.8/site-packages (6.1.0)

于是,接着尝试在/usr/local/python3/lib/python3.8/site-packages目录下,通过vi ipython-6.1.0-py3.8.egg-info修改Version: 6.1.0为Version: 6.1.111,发现再使用./pip3 install ipython安装,提示变为…(6.1.111),由此可见,ipython-6.1.0-py3.8.egg-info文件在修复该问题过程中起了阻碍作用。
通过mv命令重命名这个文件,重新执行./pip3 install ipython后,通过./ipython3命令可以进入ipython3。
重新安装ipython及验证安装过程如下:

[root@localhost bin]# ./pip3 install ipythonCollecting ipython
Using cached ipython-7.16.1-py3-none-any.whl (785 kB)
Collecting jedi>=0.10
	Using cached jedi-0.17.2-py2.py3-none-any.whl (1.4 MB)
Requirement already satisfied: pygments in /usr/local/python3/lib/python3.8/site-packages (from ipython) (2.6.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (3.0.5)
Collecting backcall
  Using cached backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: decorator in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.4.2)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.8.0)
Requirement already satisfied: setuptools>=18.5 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (41.2.0)
Requirement already satisfied: pickleshare in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.3.3)
Collecting parso<0.8.0,>=0.7.0
Using cached parso-0.7.0-py2.py3-none-any.whl (100 kB)
Requirement already satisfied: wcwidth in /usr/local/python3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/python3/lib/python3.8/site-packages (from pexpect; sys_platform != "win32"->ipython) (0.6.0)
Requirement already satisfied: ipython-genutils in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (0.2.0)
Requirement already satisfied: six in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (1.15.0)
Installing collected packages: parso, jedi, backcall, ipython
Successfully installed backcall-0.2.0 ipython-7.16.1 jedi-0.17.2 parso-0.7.0
[root@localhost bin]# ./pip3 install ipython
Requirement already satisfied: ipython in /usr/local/python3/lib/python3.8/site-packages (7.16.1)
Requirement already satisfied: pygments in /usr/local/python3/lib/python3.8/site-packages (from ipython) (2.6.1)
Requirement already satisfied: jedi>=0.10 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.17.2)
Requirement already satisfied: backcall in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.2.0)
Requirement already satisfied: pickleshare in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.7.5)
Requirement already satisfied: decorator in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.4.2)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (3.0.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.3.3)
Requirement already satisfied: setuptools>=18.5 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (41.2.0)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.8.0)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /usr/local/python3/lib/python3.8/site-packages (from jedi>=0.10->ipython) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/python3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: six in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (1.15.0)
Requirement already satisfied: ipython-genutils in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (0.2.0)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/python3/lib/python3.8/site-packages (from pexpect; sys_platform != "win32"->ipython) (0.6.0)
[root@localhost bin]# ./ipython3
Python 3.8.3 (default, Jul 20 2020, 19:47:15) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: a = input()                                                      
2+3
In [2]: a                                                                
Out[2]: '2+3'

创建软链接(https://blog.csdn.net/xhx94/article/details/98865598),并测试ipython3:

[root@localhost bin]# ln -s /usr/local/python3/bin/ipython3 /usr/bin/ipython3
[root@localhost bin]# ipython3
Python 3.8.3 (default, Jul 20 2020, 19:47:15) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: num = input('Please input a number:')                            
Please input a number:100+200

In [2]: num                                                              
Out[2]: '100+200'

三、原因分析

疑似原因:多个python版本导致安装pip时出现版本混乱,以及使用pip install ipython命令安装时,版本选择也产生混乱。

待最终确认。

四、欢迎交流

路过清楚问题原因的小伙伴,烦请留下你的宝贵经验吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 `create_engine` 方法创建 SQLAlchemy 引擎对象可以连接到数据库,并允许你执行 SQL 查询和操作数据库。 以下是使用 `create_engine` 方法的基本语法: ```python from sqlalchemy import create_engine # 创建一个引擎对象 engine = create_engine('dialect+driver://user:password@host:port/database') ``` - `dialect`:数据库类型,例如 `mysql`、`sqlite`、`postgresql` 等。 - `driver`:驱动程序,帮助 SQLAlchemy 与数据库交互。 - `user`:用户名。 - `password`:密码。 - `host`:连接的主机名。 - `port`:连接的端口号。 - `database`:要连接的数据库名称。 例如,连接到本地 SQLite 数据库: ```python from sqlalchemy import create_engine # 创建一个引擎对象 engine = create_engine('sqlite:///example.db') ``` 连接到远程 MySQL 数据库: ```python from sqlalchemy import create_engine # 创建一个引擎对象 engine = create_engine('mysql+pymysql://user:password@host:port/database') ``` 连接到远程 PostgreSQL 数据库: ```python from sqlalchemy import create_engine # 创建一个引擎对象 engine = create_engine('postgresql://user:password@host:port/database') ``` 连接到远程 Oracle 数据库: ```python from sqlalchemy import create_engine # 创建一个引擎对象 engine = create_engine('oracle://user:password@host:port/database') ``` 创建完引擎对象后,你可以使用 `execute` 方法来执行 SQL 查询和操作数据库。例如,执行一个查询: ```python result = engine.execute('SELECT * FROM my_table') ``` 这将返回一个 `ResultProxy` 对象,你可以使用它来获取查询结果。例如,获取查询结果的所有行: ```python rows = result.fetchall() ``` 或获取查询结果的第一行: ```python row = result.fetchone() ``` 你还可以使用 `execute` 方法来执行 SQL 插入、更新或删除操作。例如,插入一行数据: ```python engine.execute("INSERT INTO my_table (column1, column2) VALUES ('value1', 'value2')") ``` 更多关于 SQLAlchemy 的详细信息请参考官方文档:https://docs.sqlalchemy.org/en/14/core/engines.html

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值