Have been using ActivePython on windows7 and lxml seems working without an issue..
There were a lot of other third party packages I had & they were working too..
Until I wanted to use it inside Web2Py.
All the others seem to be working if I copy them directly inside c:/web2py/applications/myApp/modules
With lxml, seems I need to copy something else..
I have a third party module, which imports lxml like this : from lxml.etree import tostring
It ends up throwing - No module named lxml.etree
My test program outside web2py runs without an issue with both these modules.
When I do a pypm files lxml I see this :
%APPDATA%\Python\Python27\site-packages\lxml-2.3-py2.7.egg-info
What else should I copy along with the lxml directory into the modules directory ?
Pretty sure it's me doing something wrong instead of Web2py, but can't put a finger on..
web2py version = Version 1.99.7 (2012-03-04 22:12:08) stable
If you are using the Windows binary version of web2py, it comes with its own Python 2.5 interpreter and is self-contained, so it won't use your system's Python 2.7 nor see any of its modules. Instead, you should switch to running web2py from source. It's just as easy as the binary version -- just download the zip file and unzip it. You can then import lxml without moving anything to the application's /modules folder.
Related
[Edit]: My problem is unrelated to what I’m asking here. My machine has python 2.7 and 3.6 installed. Requests module was installed for 2.7 site-packages but not 3.6
I’m trying to import requests into a sub directory. I’m not aware of the best way to do this
My folder structure is
Project
- project1
- sub1
- sub1.py <—- trying to use requests here
- tests
But in the future if I want to use requests across the whole project, what’s the most effective was to import it?
If you're importing a third-party module, it's fine to just have e.g. import requests at the top of any .py file where you want to use it. As long as it's installed for your project (e.g. you've done pip install requests) you can use it wherever you want.
If you're importing your own code from one place in your project to use in another place, that can require a bit more thought, but I don't think that's your question here.
I am developing a plugin for a multi-platform Python program (Deluge). My plugin needs to import some modules which aren't available by default (in my case, the requests module).
On Linux, everything works flawlessly assuming the required modules are installed beforehand (e.g. via pip).
On Windows, the program makes use of python27.dll which comes as part of the installer, so importing modules - even those available on the local Python installation (verified via interpreter) - yields an import error.
I've seen the answers to this question, but I'd like to know if there is a proper way of adding module search paths for Python on Windows specifically. Is it safe to assume C:\Python27\Lib\site-packages will point me to the local Python installation's modules?
EDIT: Is there a different method I could incorporate for using "external" modules? Could I perhaps package other modules into my final .egg file? Not just plain Python, but more sophisticated modules like requests which need to be properly built and may even rely on other modules.
My question seems somewhat inane, but I cannot seem to find any resources for what I need to do.
Essentially I'm using my work computer to write python applications in my spare time. I'm using Python Portable (syntax version 3.2) because I do not have administrative access and can't do things with path variables etc.
How (if possible) do I install or import selenium so I can use it in Python Portable?
Thanks all!
Based on answer found Importing modules on portable python
and How to install external libraries with Portable Python?
Check for what import sys; print sys.path says?
It displays the list of directories and zipfiles where portable python looks for modules to import. Just copy your modules into one of those directories or zipfiles, or sys.path.append('/whatever/dir') if you have your modules in /whatever/dir and want to keep them there (the latter approach will last only for the current session, be it interactive or a script's execution).
Also on their FAQs
You don’t have package I need, can I add it?
For simpler packages you can use easy install or even extract them in site-packages folder of
the Portable Python distribution. However some packages are installing additional dependencies
in windows system folders - in this case your Portable Python distribution will not work once
you move it to some other workstation. Make sure to do proper testing !
I want to write a Python program that makes use of the lxml library (see http://lxml.de/). Of course I want to share my program with others and want to run it on different computers.
Now, I have a folder containing the lxml modules and a python file that does an import. Now, this import does not work and throws an Exception. You can see all the details and an overview in the following image:
http://www.qpic.ws/images/pythonprob.png
Searching for this error, recommendations were to put the path to the lxml source folder in to my PATH. But: I want the program to work on different computers without having to manipulate their PATHes/PYTHONPATHes! The module should just be referenced in a local context, that means, should just reside in a folder next to my program. I think, it does not really matter whether it is lxml or an other third party module collection.
Am I understanding something bitterly wrong or is there a simple solution to my needs?
System:
Python 3.3
• Windows 7
Thanks in advance!
Install LXML inside a virtualenv, and run your program from that environment. This will handle your PATH issue seamlessly. On different computers, you can build new virtualenvs and install dependencies.
lxml.etree is a compiled extension. It is not enough to put the lxml source folder into sys.path.
Try to download lxml-3.0.2.win-amd64-py3.3.exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml, open the installer file with an unzip program, e.g. WinRAR, and replace the current lxml source directory with the lxml folder in the installer.
I have built a Python application using an external library (lxml-module). This runs fine in my system. Is there any way to compile this code or package this code, so that I can run it in another system which does not have this external library (lxml-module) module installed in it?
If possible please give me a little reference on *.pyd also?
PyInstaller would be a good way to go to package your code.
It works in a configure/make/build workflow (before which you setup a small spec file with different kinds of options). The external package will be shipped along with your application.
lxml is supported in PyInstaller: http://www.pyinstaller.org/wiki/SupportedPackages.
As for being able to compile your code on another machine, Marcin had a good suggestion.
You can always copy the module to your local path and import it from there. Kind of what django did for json until it was included in the standard library.
This could do the trick:
try:
import lxml
except ImportError:
import myownmodules.lxml as lxml
I know this is the less "high tech" approach but if the problem is simple enough this is what I would do without a blink.
Besides .... our buddy Tim seems to agree: "If the implementation is easy to explain, it may be a good idea."
For Windows package up using py2exe, for OSX use py2app and for Linux possibly use cx_freeze