首页 > 解决方案 > 执行 Python 模块而不安装它

问题描述

我们如何在没有安装 pandas 的环境中运行实现 pandas 模块的 python 脚本?

例如,在服务器上,我们无权安装 python 模块。我们有一个使用 pandas 模块的脚本,那么我们如何运行这些脚本呢?

标签: pythonpandasinstallation

解决方案


In short: no, you can't. You have to install the package.

There are at least two options. First, you can install the packages that are not in the system to your home dir (but this is messy and dependent on the changes to the OS-level setup). You use:

pip install --user pandas 

However, a better way is to use virtual environment (e.g. venv):

python -m venv local-env

In this way you can create a local copy of Python environment in which you can install pandas and any other dependencies of your code. And it is fully under your control.

On venv you can read more in the Python documentation.


推荐阅读