PyODPS is the Python SDK for MaxCompute. It provides basic operations on MaxCompute objects and a DataFrame framework for Python-based data analytics. Use PyODPS in DataWorks or in a local environment. This topic covers local environment installation.
Prerequisites
Before you begin, make sure you have:
-
Python 3.6 or later installed
-
An Alibaba Cloud account with a RAM user AccessKey (used to authenticate to your MaxCompute project)
Install PyODPS
-
Install PyODPS.
Linux/macOS
pip3 install pyodpsWindows
pip install pyodpsNoteIf you see a C compilation error during installation — typically caused by outdated pip or setuptools — upgrade them first, then retry:
# Linux/macOS pip3 install -U pip setuptools # Windows pip install -U pip setuptools -
Verify the installation.
Linux/macOS
python3 -c "from odps import ODPS"Windows
python -c "from odps import ODPS"No output means the installation succeeded. If an error appears, see Troubleshooting.
Set environment variables
Your AccessKey acts as the identity credential to access a MaxCompute project. Store it as an environment variable rather than hardcoding it in your code.
Log in to the Resource Access Management (RAM) console and copy your AccessKey ID and AccessKey secret, then follow the steps for your operating system.
macOS (zsh)
-
Open the zsh configuration file.
# If zsh is not installed, run: brew install zsh vim ~/.zshrc -
Add the following lines, replacing the placeholders with your actual values.
export ALIBABA_CLOUD_ACCESS_KEY_ID=<your-AccessKey-ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<your-AccessKey-secret> -
Apply the changes.
source ~/.zshrc -
Confirm the variables are set.
echo $ALIBABA_CLOUD_ACCESS_KEY_ID echo $ALIBABA_CLOUD_ACCESS_KEY_SECRETEach command prints the corresponding value. If either prints nothing, repeat steps 2 and 3.
For additional details on setting environment variables on Linux, macOS, and Windows systems, see Set an Alibaba Cloud AccessKey in an environment variable.
What's next
Use PyODPS in a local environment to start building with MaxCompute.
Troubleshooting
Dependency package installation errors
Symptom: A C code compilation error appears when installing numpy, pyarrow, or other dependency packages.
Cause: pip or setuptools is outdated.
Fix: Upgrade pip and setuptools, then reinstall PyODPS.
# Linux/macOS
pip3 install -U pip setuptools
# Windows
pip install -U pip setuptools
pip version conflicts for different Python versions
Symptom: PyODPS installs against the wrong Python version.
Cause: The system has multiple Python versions and pip3 targets a different one than intended.
Fix: Call pip through the specific Python executable.
/home/tops/bin/python3.7 -m pip install pyodps
Replace /home/tops/bin/python3.7 with the path to your target Python installation.
urllib3 OpenSSL version error
Symptom: Installation fails with urllib3 v2.0 only supports OpenSSL 1.1.1+.
Cause: Your Python installation uses an older OpenSSL version that is incompatible with urllib3 v2.0.
Fix: Install an earlier urllib3 version first, then install PyODPS.
# Linux/macOS
pip3 install "urllib3<2.0"
# Windows
pip install "urllib3<2.0"