Pyramid框架Python Web应用本地运行失败及依赖安装问题求助
Hey there, let's break down and fix the issues you're facing with your PyVac Pyramid app step by step.
The error about unsatisfied package requirements is probably a mix of outdated package versions not playing nice with Python 3.5, and missing system-level dependencies (especially for packages like python-ldap and lxml). Here’s how to tackle this:
a. Update Package Versions for Python 3.5 Compatibility
Most of the specified versions are pretty old (like Pillow 2.2.2 from 2013) and might not fully support Python 3.5. Try tweaking your requirements file with these more recent, compatible versions:
- Replace
Pillow==2.2.2withPillow>=3.0.0(3.x versions and above support Python 3.5) - Swap
lxml==3.3.2forlxml>=3.4.0 - Upgrade
python-ldap==2.4.14topython-ldap>=2.4.20(the first version with solid Python 3.5 support) - For
Criptacular==1.4.1, useCriptacular>=1.4.1(check if newer versions exist, or confirm 1.4.1 works with Python 3.5) - Replace
simplejson==2.6.2withsimplejson>=3.8.0(fully supports Python 3.5)
Modify your project's requirements file (like requirements.txt) with these changes, then run:
pip install -r requirements.txt
b. Install System-Level Dependencies
Packages like python-ldap and lxml need system libraries to build successfully. Install them based on your operating system:
- Ubuntu/Debian:
sudo apt-get install libldap2-dev libsasl2-dev libxml2-dev libxslt1-dev - CentOS/RHEL:
sudo yum install openldap-devel libxml2-devel libxslt-devel - Windows:
Use pre-built wheels from trusted sources that provide binaries for Python packages (look for wheels matching Python 3.5 and your system architecture). Once downloaded, install it with:pip install path/to/wheel-file.whl
PyCharm Community Edition fully supports virtual environments—you just might need to configure it properly:
Step 1: Create or locate your virtual environment
If you haven’t already, make a Python 3.5 virtual environment:python3.5 -m venv pyvac-envActivate it:
- Linux/macOS:
source pyvac-env/bin/activate - Windows:
pyvac-env\Scripts\activate
- Linux/macOS:
Step 2: Link the virtual environment to PyCharm
- Open your PyVac project in PyCharm
- Go to
File > Settings > Project: pyvac > Python Interpreter - Click the gear icon →
Add - Select
Virtualenv Environment, then chooseExisting environment - Browse to the
pythonexecutable inside your virtual environment (e.g.,pyvac-env/bin/pythonon Linux,pyvac-env\Scripts\python.exeon Windows) - Hit
OKto save the configuration
Step 3: Run your Pyramid app from PyCharm
Once the interpreter is set up, you have two options:- If the project has an entry script (like
main.pyorapp.py), right-click it and selectRun 'script_name' - If it uses Pyramid’s
pservecommand, add a custom run configuration:- Go to
Run > Edit Configurations - Click
+→Python - Set
Script pathto thepserveexecutable in your virtual environment (e.g.,pyvac-env/bin/pserve) - Add your Pyramid config file as
Parameters(likedevelopment.ini) - Click
OKand run the configuration
- Go to
- If the project has an entry script (like
Even though you upgraded pip to 10.0.1, make sure you’re using the pip from your virtual environment. Run:
pip --version
It should show something like pip 10.0.1 from /path/to/pyvac-env/lib/python3.5/site-packages/pip (python 3.5). If not, reactivate your virtual environment and upgrade pip inside it:
pip install --upgrade pip==10.0.1
If you still hit snags, check the project’s README for any specific setup steps you might have missed—Pyramid projects sometimes require extra steps like initializing a database or setting environment variables.
内容的提问来源于stack exchange,提问作者Andrei Razvan

