ImportError: No module named lxml on Mac OSX 10.11 - python

I just bought a new Mac Book Pro with OSX 10.11 El Capitan.
I'm running Google App Engine Launcher python for local dev, which is where I see this in the logs when it reaches import lxml.
"ImportError: No module named lxml"
I followed the instructions from the lxml website
sudo pip install lxml
Package installs but can't be seen on path by python. I updated my path in .bashrc and .bash_profile with:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/python2.7/site-packages/:$PATH
Then found this article Installing lxml on Mac OSX (10.11) inside a virtualenv with pip
$ STATIC_DEPS=true pip install lxml
Again it installs but can't be found.
I even tried compiling from source and installing macports as it got it embedded, but still no luck.
I read the lxml team is frustrated with OSX and the mess with its outdated libraries and all.
UPDATE
In relation to the comments made, its not a app.yaml libraries declaration, and its unlikely an issue specific to GAE, as it seems more likely between python and oxs-elcapitan.
also I get this unusual message
The directory '/Users/[username]/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
I tried with sudo -H but that didn't resolve the paths either.
But it does suggest the changes in 10.11 might be part of the problem.

AppEngine uses it's own environment that reflects their server and does not see libraries that you've installed locally.
To see the package it should be located in the root of the project (where the app.yaml is located).
But there is also runtime provide libraries- read section "Using Runtime-Provided Libraries with the Local Development Server" at https://cloud.google.com/appengine/docs/python/tools/libraries27
Probably you would need to add to app.yaml:
libraries:
- name: lxml
version: "2.3.5"

STATIC_DEPS didn't work for me (looks like the relevant FTP sites were down?), but this did the trick:
C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:$C_INCLUDE_PATH pip install lxml

Related

ImportError: No module named google.cloud.error_reporting

A few weeks ago I've installed Ubuntu 18.10 at home and today I decided to move from Windows to this OS at home.
I use it for Python development.
Unfortunately, I faced with some strange error and don't know how to solve it.
When I try to run my project I see next error during simple request
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1154, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named google.cloud.error_reporting
When I run pip show google_cloud_error_reporting it shows me proper info about the package
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: google-cloud-error-reporting
Version: 0.30.1
Summary: Stackdriver Error Reporting API client library
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google LLC
Author-email: googleapis-packages#google.com
License: Apache 2.0
Location: /home/p35/.local/share/virtualenvs/tt-T7X9xdJU/lib/python2.7/site-packages
Requires: google-cloud-logging
Required-by:
Output from gcloud --version
Google Cloud SDK 240.0.0
alpha 2019.03.22
app-engine-python 1.9.84
app-engine-python-extras 1.9.84
beta 2019.03.22
bq 2.0.42
cloud-datastore-emulator 2.1.0
core 2019.03.22
gsutil 4.37
kubectl 2019.03.22
I tried to reinstall pipenv, setuptools, project dependencies itself, but nothing helps me.
Simplified project https://github.com/pahan35/google-cloud-error-reporting-import-bug
Any idea how to fix this problem?
I've found a workaround for this problem: we should add google dependencies via vendor.add([any_accessible_folder]) and then either run a project under another interpreter or we need to remove all google dependencies from the current pipenv interpreter.
Workaround (right solution still welcome)
For this specific project I did next steps.
Common steps
Install all pipenv dependencies to lib folder via command
pipenv run pip install -r <(pipenv lock -r) -t lib --upgrade
Use your local folder as another source of packages in your entry file before imported google cloud dependency
from google.appengine.ext import vendor
vendor.add('lib')
from google.cloud import error_reporting # causing problems dependency
Then you need either remove google packages from your pipenv interpreter or use another one. I tested both: B is easier but may cause unexpected conflicts or missed packages
A. Clear current pipenv interpreter from all google cloud dependencies
Enter into pipenv shell via command pipenv shell
See installed packages via pip list
Remove all google cloud packages plus some extra noticed via iterated runs
pip uninstall google_cloud_error_reporting google_auth google_core google_cloud_core google_api_core google_cloud_logging googleapis_common_protos protobuf
Maybe we can optimize it via removing all packages from pipenv interpreter?
B. Use another interpreter
Find absolute path to desirable interpreter. I used a global one /usr/bin/python
Run the project via this interpreter like /usr/bin/python $(which dev_appserver.py) .
Project
Example project contains applied workaround

How do I install a Python library? [duplicate]

I'm having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don't have an executable for Python 2.6.
For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!
The accepted answer is outdated. So first, pip is preferred over easy_install, (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it's quite easy.
Install setuptools:
curl https://bootstrap.pypa.io/ez_setup.py | python
Install pip:
curl https://bootstrap.pypa.io/get-pip.py | python
Optionally, you can add the path to your environment so that you can use pip anywhere. It's somewhere like C:\Python33\Scripts.
Newer versions of Python for Windows come with the pip package manager. (source)
pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4
Use that to install packages:
cd C:\Python\Scripts\
pip.exe install <package-name>
So in your case it'd be:
pip.exe install mechanize
This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.
You don't need the executable for setuptools.
You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt
Starting with Python 2.7, pip is included by default. Simply download your desired package via
python -m pip install [package-name]
As I wrote elsewhere
Packaging in Python is dire. The root cause is that the language ships without a package manager.
Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby's Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.
So the right thing to do is to install pip. However if you can't be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/
In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.
I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.
Firstly, you'll need to add python installation to your PATH variable. This should help.
You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
Run the command python setup.py install
That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.
Upgrade the pip via command prompt ( Python Directory )
D:\Python 3.7.2>python -m pip install --upgrade pip
Now you can install the required Module
D:\Python 3.7.2>python -m pip install <<yourModuleName>>
pip is the package installer for python, update it first, then download what you need
python -m pip install --upgrade pip
Then:
python -m pip install <package_name>
You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.
PS D:\simcut> C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
InsecurePlatformWarning
Or just put the directory to your pip executable in your system path.
As mentioned by Blauhirn after 2.7 pip is preinstalled. If it is not working for you it might need to be added to path.
However if you run Windows 10 you no longer have to open a terminal to install a module. The same goes for opening Python as well.
You can type directly into the search menu pip install mechanize, select command and it will install:
If anything goes wrong however it may close before you can read the error but still it's a useful shortcut.

Cant find pg_config even after installing Postgres 9.5

I have been trying to debug this for quite a while now (and read lots of related Q/A on StackOverflow) but unable to figure this out.
Trying to setup Django on my Mac OS X 10.11.6. I followed the detailed tutorial. This is what I did:
1) Installed Python 3.5.2 (by directly downloading the package from the Python web site and running it).
2) Installed PostGres 9.5 using the fink package (fink install postgresql95)
3) Installed psycopg2 using the fink package (fink install psycopg2-py35).
4) Updated pip.
5) Setup a virtual environment and activated it.
6) After activating the environment, installed Django (via pip).
Next, when I tried to setup a sample app in the environment and ran python manage.py migrate, it gave me the error : Error loading psycopg2 module: No module named 'psycopg2'
After reading a lot of posts on StackOverflow, it seemed that I have to install psycopg2 again within the virtualenv (and for some reason, I cant use Fink again?). So as suggested on some posts, I tried to install it using:
pip install psycopg2
Got this error:Error: pg_config executable not found.
I am sure my Fink install of Postgres 9.5 was successful earlier, so I tried to search for pg_config from root dir:
sudo find . -name "pg_config"
But it returned nothing!
My question is, is it possible that fink package did not come with pg_config? If it didnt, is my only option now to uninstall postgres and install it with another package? (FYI: I was able to start PostGres and create a user and a database on it already)
Thanks in advance,
Anupam
Update: After waiting a while to get answers from SO, I gave up and just uninstalled the postgres fink package. Then installed the postgres.app instead, on my mac. Working fine for me. The command python manage.py migrate worked fine for me this time and the psycopg2 installation also went fine (with pip). I wonder why the psycopg2 installation page (http://initd.org/psycopg/docs/install.html#installation) only mentions Fink and MacPorts as the installation options especially when the Fink packages dont seem to be very reliable. I had posted a message on the Fink users group also about improving the installation documentation in another context but didnt get a response : (

ImportError: No module named requests - Python

I get an error message when I run the following line of code
import requests
Here is the error message
Traceback (most recent call last):
File "C:\Python27\test", line 1, in <module>
import requests
ImportError: No module named requests
Based on what I've seen from other posts, the common reason for the problem is individuals download the requests module but have not installed it. I downloaded the tarball, unzipped it and installed the setup.py file via the computer command line. There is a requests-2.4.0-py2.7.egg folder in the Python27/Lib/site-packages folder.
For Windows, install pip. You'll probably need other packages later on, so it will pay off to have a proper package manager.
Here is the documentation: https://pip.pypa.io/en/latest/index.html
You might actually be missing certifi module.
Overview:
From your error stack trace, it appears that you are using Windows platform and have the native windows Python installation. So I will stick to Windows instructions here. But since I have Cygwin based python installation, I will provide here cygwin-based steps to resolve your issue.
However, you can very easily use these steps on the Windows command prompt as well, by installing pip or easy_install, pre-built binary, or source code.
Windows-Cygwin-Pip way:
Add the directory that hosts python executable to your environment's PATH variable. Instructions here
Get pip to easily install new python packages. Best way is to download get-pip.py in cygwin’s home directory and run python get-pip.py in cygwin bash shell command prompt. Detailed and Alternative instructions here
Run pip install requests in the cygwin bash shell. It will install requests and certifi packages, which results in results, requests-2.4.0.dist-info, certifi, and certifi-14.05.14-py2.7.egg-info in the /lib/site-packages folder.
Run python and execute your original line of code import requests. It will run without errors.
Alternatives Ways to Installing a New Package:
There are several other alternatives of downloading this requests package, or for that matter any new python package. These include:
Getting easy_install in Cygwin and Running easy_install requests. Get easy_install in cygwin by installing setuptools package or by following instructions here.
Downloading a pre-built binary available here. And running it as executable. It will automatically install the module under the latest python installation available in windows registry.
Downloading source code for requests from Github into the home directory and Running python setup.py install
Python-Requests Installation Doc:
There is a brief list of ways to install requests available on the original python-requests project website as well. See here.
For a more productive environment and saving lots of headaches, follow these steps:
Install virtualenv
Install virtualenvwrapper
Always manage your environments with virtualenvwrapper
Always use pip to install dependencies inside your virtual environment
Use 'pip freeze --local' to see what's installed or to produce a requirements.txt file (pip freeze --local > requirements.txt )
If you have no idea what I'm talking about, you should spend some time reading up on these things, and you'll discover one of the many things that makes python so nice to work with (well, ok other programming languages have similar tools)

How to install lxml.etree directly to web2py modules?

I have a working setup of lxml.etree working on my windows desktop.
Since I wanted to move this to my server, instead of installing lxml in sitepackages, I wanted to install it inside the modules directly, so this lxml version is specific to this applicaion/site.
I copied my lxml directory directly under modules on the linux server, and I got this error :
No module named etree
So it seems it understood there is an lxml, package but couldn't see etree inside it.
Any ideas ?
Also, I couldn't find exactly where I can download the binaries for ubuntu 9.10 on the site : http://lxml.de/installation.html#installation
You can't just copy the Windows version over to a Linux server; lxml uses C extensions which need to be compiled for the target platform.
The etree module is such a compiled extension, on Linux that'd be etree.so, while on Windows it would be a etree.dll file instead, for example.
For Ubuntu, look for python-lxml, or install the dependencies libxml2-dev, libxslt1-dev and python-dev, plus python-pip, then use sudo pip install lxml to install lxml on your server.

Categories

Resources