How to install NodeBox for console - python

I'm working on OS X Mavericks and want to use the NodeBox modules in Python scripts.
The post about how to install the modules for console is from 2009 and doesn't work anymore as this refers to version 1.9.x (current is 3.0.40). Also the SVN source isn't there anymore. The sources are available at GitHub.
By cloning the project and running:
ant run
all I get is a build of the desktop version.
How do I properly install and run the up to date NodeBox modules in Python scripts?

As said in the docs here in section 2. Installing the NodeBox module:
If you want to use NodeBox from the command line, you will have to install it. We currently recommend using Subversion to grab a copy:
svn co http://dev.nodebox.net/svn/nodebox/trunk/ nodebox
...
cd src
python setup.py install
we should be installing the usual way from the source, but as you say the procedure is rather outdated. The source apparently moved from SVN to GitHub at https://github.com/nodebox/nodebox-pyobjc as mentioned on the download page and the source package structure changed too.
Let's grab the source and try to install it:
$ git clone https://github.com/nodebox/nodebox-pyobjc.git
$ cd nodebox-pyobjc
$ python nodebox/setup.py install
Traceback (most recent call last):
File "nodebox/setup.py", line 17, in <module>
import nodebox
ImportError: No module named nodebox
So setup.py needs to import the nodebox package, let's add the project root dir to Python path, so that the nodebox package can be found and try again:
$ export PYTHONPATH=$PYTHONPATH:.
$ python nodebox/setup.py install
...
clang: error: no such file or directory: 'nodebox/ext/cGeo.c'
clang: error: no input files
error: command 'clang' failed with exit status 1
Now it turns out some lib paths in setup.py are wrong, no one probably used this for some time while the libs moved around, but we can fix it:
# ext_modules = [
# Extension('cGeo', ['nodebox/ext/cGeo.c']),
# Extension('cPathmatics', ['nodebox/ext/cPathmatics.c']),
# Extension('cPolymagic', ['nodebox/ext/gpc.c', 'nodebox/ext/cPolymagic.m'], extra_link_args=['-framework', 'AppKit', '-framework', 'Foundation'])
# ]
ext_modules = [
Extension('cGeo', ['libs/cGeo/cGeo.c']),
Extension('cPathmatics', ['libs/pathmatics/pathmatics.c']),
Extension('cPolymagic', ['libs/polymagic/gpc.c', 'libs/polymagic/polymagic.m'], extra_link_args=['-framework', 'AppKit', '-framework', 'Foundation'])
]
Try install again:
$ python nodebox/setup.py install
...
running install_egg_info
Writing <python>/lib/python2.7/site-packages/NodeBox-1.9.7rc2-py2.7.egg-info
$ pip list
...
NodeBox (1.9.7rc2)
...
Now the package installed successfully and we should be able to use it:
$ python
>>> import nodebox
>>> dir(nodebox)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'get_version']
>>> nodebox.__version__
'1.9.7rc2'
Also, you may still need to manually install some of the dependencies for everything to work correctly, as noted in setup.py itself:
# We require some dependencies:
# - PyObjC
# - psyco
# - py2app
# - cPathMatics (included in the "libs" folder)
# - polymagic (included in the "libs" folder)
# - Numeric (included in the "libs" folder)
# - Numpy (installable using "easy_install numpy")
I already created a pull request with fixed setup.py lib paths, see here.
Tested on OS X Mavericks (System Version: OS X 10.9.3 (13D65), Kernel Version: Darwin 13.2.0) using Homebrew Python 2.7.6.

Related

Cannot install custom python module

I am having trouble installing a custom python module I have written.
Here are my steps so far:
Navigate to the module directory C:\Users\myname\repos\mymodulename where the setup.py file is in the anaconda prompt. Type: python setup.py install
The command prompt returns (plus some other things)
Extracting mymodulename-0.1-py3.7.egg to c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages
mymodulename 0.1 is already the active version in easy-install.pth
Installing myclass-script.py script to C:\Users\myname\AppData\Local\Continuum\anaconda3\Scripts
Installing myclass.exe script to C:\Users\myname\AppData\Local\Continuum\anaconda3\Scripts
Installed c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages\mymodulename-0.1-py3.7.egg
Processing dependencies for mymodulename==0.1
...
Using c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages
Finished processing dependencies for mymodulename==0.1
To me that looks like it has installed. Opening up the console and trying to import:
>>> import mymodulename.myclassas ce
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mymodulename'
>>>
It appears in hasn't. Checking the list of modules in anaconda with help('modules') confirms that it has not been imported.
I thought that perhaps i had installed it to the wrong environment:
(base) C:\Users\myname>conda env list
# conda environments:
#
base * C:\Users\myname\AppData\Local\Continuum\anaconda3
py2 C:\Users\myname\AppData\Local\Continuum\anaconda3\envs\py2
Only a python 2 environment which mymodule wouldn't be compatible with.
Does anyone have any suggestions about what I can try to resolve this? Happy to elaborate on any of the points
Thanks in advance.
EDIT: Some more information that may be relevant.
This package was initially installed in site-packages. I have reinstalled there and the package works. The reason I moved the package is because I am aware it is bad practice to store custom packages there.

How to make python update module install dir after moving folder?

I installed a Python module from GitHub. Here is an example of the commands I ran:
cd ~/modules/
git clone https://github.com/user/xyz
cd xyz
python setup.py develop
this installed the the module succesfully in the current folder. Then from some other folder, I did:
cd ~/test
python -c 'import inspect; import xyz; print(inspect.getfile(xyz))'
wich gave the following output:
/home/hakon/modules/xyz/xyz/__init__.py
Now, I decided I wanted to move the install folder. For example,
cd ~/modules/xyz
mv xyz xyz2
But now Python cannot find the module any longer. For example:
cd ~/test
python -c 'import inspect; import xyz; print(inspect.getfile(xyz))'
With output:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'xyz'
Questions:
Where does Python register the location of modules?
How can I update the registry to the new location of the module?
According to the documentation for setup tools develop command:
The develop command works by creating an .egg-link file (named for the
project) in the given staging area. If the staging area is Python’s
site-packages directory, it also updates an easy-install.pth file so
that the project is on sys.path by default for all programs run using
that Python installation.
So to answer the question to update the location after you have moved the project folder you can rerun the develop command (from the new folder):
python setup.py develop
Note: you could also unregister the project before you moved it:
python setup.py develop --unistall
but this is not necessary if you just want to update the location.

Package Python script in virtualenv into a Debian package

I'm going crazy with this. I have a small script witch simply tells me the firefox profile name. As I said this is only a test, just for test how does it work until starting the real job. What we need is to deploy this script into a deb package to install them in all clients in our company (ubuntu mate).
I have to say that is the first time I work with python, so maybe the setup.py isn't correct either. I created a virtualenv in my izenpe folder, and installed a module with
pip install mozprofile
This is my folder structure:
izenpe/
- izenpemiddleware.py
- setup.py
- debian/
- compat
- control
- izenpemiddleware.triggers
- rule
This is my izenpemiddleware.py
import sys
import mozprofile
def main(args=None):
"The main routine."""
if args is None:
args = sys.argv[1:]
pro = mozprofile.Profile()
print "Perfila da:\n"
print "*************"
print pro.profile
print "*************"
if __name__ == "__main__":
main()
And this is my setup.py (is it ok?):
#!/usr/bin/env python
from setuptools import setup
from setuptools import find_packages
Description = """/
izenpe
"""
# setup parameters
setup(name='izenpemiddleware',
version='0.1',
description='Mirefox-en izenpe middleware instalatu',
long_description=Description,
packages=find_packages(),
author_email='iibarguren#pasaia.net',
classifiers=["Programming Language :: Python :: 2.7",
"Development Status:: 1 - Alpha",
'Programming Language :: Python',
],
scripts=["izenpemiddleware.py"]
)
I found this library https://github.com/benjaminirving/python-debian-packaging-example to generate deb packages from a virtualenv, so this is my config:
debian/control:
Source: izenpe
Section: python
Priority: extra
Build-Depends: debhelper (>= 9), python, dh-virtualenv, python-all-dev
Standards-Version: 3.9.5
Package: izenpemiddleware
Architecture: any
Pre-Depends: dpkg (>= 1.16.1), python2.7-minimal, ${misc:Pre-Depends}
Depends: ${python:Depends}, ${misc:Depends}, python-pyside, python-numpy
Description: Izenpe ziurtagiriak Firefox-entzat instalatu.
debian/firefoxmiddleware.triggers
# Register interest in Python interpreter changes (Python 2 for now); and
# don't make the Python package dependent on the virtualenv package
# processing (noawait)
interest-noawait /usr/bin/python2.7
# Also provide a symbolic trigger for all dh-virtualenv packages
interest dh-virtualenv-interpreter-update
debian/rules:
#!/usr/bin/make -f
%:
dh $# --with python-virtualenv
override_dh_virtualenv:
dh_virtualenv --setuptools \
--extra-pip-arg --ignore-installed \
--extra-pip-arg --no-dependencies \
--use-system-packag
After that I generated a deb package with this command:
sudo dpkg-buildpackage -us -uc -b
Debian package is created correctly. I sent this file via scp to another computer installed with
dpkg -i izenpemiddleware_0.1_amd64.deb
If I updatedb and find the script with locate izenpemiddleware.py the result is:
/usr/share/python/izenpemiddleware/bin/izenpemiddleware.py
It seems that is installed correctly, but when I launch the script I've got an error:
root#portatil-001:~# python /usr/share/python/izenpemiddleware/bin/izenpemiddleware.py
Traceback (most recent call last):
File "/usr/share/python/izenpemiddleware/bin/izenpemiddleware.py", line 2, in <module>
import mozprofile
ImportError: No module named mozprofile
Am I missing something? Any help will be appreciated.
Your setup.py needs to state its install_requires.
setup(…
install_requires=['mozprofile'],
…

pdfminer - ImportError: No module named pdfminer.pdfdocument

I am trying to install pdfMiner to work with CollectiveAccess. My host (pair.com) has given me the following information to help in this quest:
When compiling, it will likely be necessary to instruct the
installation to use your account space above, and not try to install
into the operating system directories. Typically, using "--
home=/usr/home/username/pdfminer" at the end of the install command
should allow for that.
I followed this instruction when trying to install.
The result was:
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/home/username/pdfminer/bin/latin2ascii.py to 755
changing mode of /usr/home/username/pdfminer/bin/pdf2txt.py to 755
changing mode of /usr/home/username/pdfminer/bin/dumppdf.py to 755
running install_egg_info
Removing /usr/home/username/pdfminer/lib/python/pdfminer-20140328.egg-info
Writing /usr/home/username/pdfminer/lib/python/pdfminer-20140328.egg-info
I don't see anything wrong with that (I'm very new to python), but when I try to run the sample command $ pdf2txt.py samples/simple1.pdf I get this error:
Traceback (most recent call last): File "pdf2txt.py", line 3, in <module>
from pdfminer.pdfdocument import PDFDocument ImportError: No module named pdfminer.pdfdocument
I'm running python 2.7.3. I can't install from root (shared hosting). The most recent version of pdfminer, which is 2014/03/28.
I've seen some posts on similar issues ("no module named. . . " but nothing exactly the same. The proposed solutions either don't help (such as installing with sudo - not an option; specifying the path for python (which doesn't seem to be the issue), etc.).
Or is this a question for my host? (i.e., something amiss or different about their setup)
I had an error like this:
No module named 'pdfminer.pdfinterp'; 'pdfminer' is not a package
My problem was that I had named my script pdfminer.py which for the reasons that I don't know, Python took it for the original pdfminer package files and tried to compiled it.
I renamed my script to something else, deleted all the *.pyc file and __pycache__ directory and my problem was solved.
use this command worked for me and removed the error
pip install pdfminer.six
Since the package pdfminer is installed to a non-standard/non-default location, Python won't be be able to find it. In order to use it, you will need to add it to your 'pythonpath'. Three ways:
At run time, put this in your script pdf2txt.py:
import sys
# if there are no conflicting packages in the default Python Libs =>
sys.path.append("/usr/home/username/pdfminer")
or
import sys
# to always use your package lib before the system's =>
sys.path.insert(1, "/usr/home/username/pdfminer")
Note: The install path specified with --home is used as the Lib for all packages which you might want to install, not just this one. You should delete that folder and re-install with --
home=/usr/home/username/myPyLibs (or any generic name) so that when you install other packages with that install path, you would only need the one path to add to your local Lib to be able to import them:
import sys
sys.path.insert(1, "/usr/home/username/myPyLibs")
Add it to PYTHONPATH before executing your script:
export PYTHONPATH="${PYTHONPATH}:/usr/home/username/myPyLibs"
And then put that in your ~/.bashrc file (/usr/home/username/.bashrc) or .profile as applicable. This may not work for programs which are not executed from the console.
Create a VirtualEnv and install the packages you need to that.
I have a virtual environment and I had to activate it before I did a pip3 install to have the venv see it.
source ~/venv/bin/activate

Setup.py woes: WARNING: '' not a valid package name

For my Python project, I keep my source code in the directory src. Thus, for my project's setup.py script:
from setuptools import setup
setup(name='pyIAST',
...
package_dir={'':'src'},
packages=[''])
so that it looks for src/IAST.py, where my code resides. e.g. there is a function plot_isotherms() in my IAST.py script so the user can, after installation, call it:
import IAST
IAST.plot_isotherms()
Everything works great, but there is an annoying warning when I python setup.py install or use pip install pyIAST from PyPi:
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
How do I make this go away?
My project is here. I'm also a bit confused as to why I name my package pyIAST, yet the user still types import IAST for my package to import.
One way to clear that warning is to change your first line to:
from setuptools import setup, find_packages
and then change your packages line to:
packages=find_packages(),
The setup install will no longer generate a warning.
You can run the following two commands to see your isotherm method is now available:
import pyiast #(<==notice this is not IAST)
dir(pyiast)
['BETIsotherm', 'InterpolatorIsotherm', 'LangmuirIsotherm', 'ModelIsotherm', 'QuadraticIsotherm', 'SipsIsotherm', '_MODELS', '_MODEL_PARAMS', '_VERSION', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'iast', 'np', 'plot_isotherm', 'print_selectivity', 'reverse_iast', 'scipy']
It can be called using pyiast.plot_isotherm()
You may need to update your setuptools. You can check what version you have with:
import setuptools; print "setup version: ", setuptools.__version__
Can update it with:
sudo pip install --upgrade setuptools

Categories

Resources