I'm building vtk on Cent OS. I would like to install the python wrappers, and I've followed the build directions to do so.
I've installed under prefix ~/local. Things appear to have gone successfully:
vtk, vtkpython, and other vtk executables appear in my ~/local/bin/ directory. vtk libraries appear in ~/local/lib.
However, when I run python -c "import vtk", I see:
ImportError: No module named vtk
So apparently, something is not correctly pointing to something else, although I'm not sure what I'm missing since I've followed the build directions.
Here is the value of a particular shell variable that seems to show up on a related question:
echo $LD_LIBRARY_PATH
=> ~/local/lib
Check where is the python module. In my system (where VTK was not built following those instructions, but should not be too different) there is a folder in lib/python2.6/site-packages/vtk/ , which contains __init__.py and all the vtk classes (e.g vtkCommonCore.py , vktCommonCorePython.so ..).
If you find that folder, add its parent folder to the PYTHONPATH environment variable (or in your python distribution site-packages folder, create a file vtk.pth which contains that folder).
So, in my system, I have:
export PYTHONPATH=/mypath/INSTALL/lib/python2.6/site-packages/:$PYTHONPATH
See also http://www.vtk.org/Wiki/VTK/Tutorials/PythonEnvironmentSetup
Related
I am using python 2.7.13 and
I am facing problems importing ruamel.yaml when I install it in a custom directory.
**ImportError: No module named ruamel.yaml**
The command used is as follows:
pip install --target=Z:\XYZ\globalpacks ruamel.yaml
I have added this custom directory to PYTHONPATH env variable
and also have a .pth file in this location with the following lines
Z:\XYZ\globalpacks\anotherApp
Z:\XYZ\globalpacks\ruamel
There is another app installed similarly with the above settings
and it works.
What am I missing here?
PS: It works when I install in site-packages folder
also it worked in the custom folder when I created an init.py file
in the ruamel folder.
EDIT:
Since our content creation software uses python 2.7 we are restricted to
using the same.We have chosen to install the same version of python on all
machines and set import paths to to point to modules/apps locacted on shared
network drive.
Like mentioned it works in pythons site-packages but not on the network drive
which is on the PYTHONPATH env-variable.
The ruamel.yaml-**.nspkg.pth and ruamel.ordereddict-*-nspkg.pth are
dutifully installed.Sorry for not giving complete details earlier.Your inputs
are much appreciated.
I keep getting this error in python from trying to call qgis from a script.
The code is:
from qgis.core import *
from qgis.analysis import *
I have read every posting on SO about this; wiped QGIS and reinstalled. Reset my PYTHON_PATH and QGIS_PREFIX variables to the correct directory. I've also checked the dependencies via dpkg -l | grep qgisand all of my dependencies are the xenial version.
Any other suggestions?
I had the same problem but it was with Windows 7. Following the last point called Running Custom Applications in http://docs.qgis.org/2.8/en/docs/pyqgis_developer_cookbook/intro.html I solved it.
You will need to tell your system where to search for QGIS libraries and appropriate Python modules if they are not in a well-known location — otherwise Python will complain:
>>> import qgis.core
ImportError: No module named qgis.core
This can be fixed by setting the PYTHONPATH environment variable. In the following commands, qgispath should be replaced with your actual QGIS installation path:
on Linux: export PYTHONPATH=/qgispath/share/qgis/python
on Windows: set PYTHONPATH=c:\qgispath\python
The path to the PyQGIS modules is now known, however they depend on qgis_core and qgis_gui libraries (the Python modules serve only as wrappers). Path to these libraries is typically unknown for the operating system, so you get an import error again (the message might vary depending on the system):
>>> import qgis.core
ImportError: libqgis_core.so.1.5.0: cannot open shared object file: No such file or directory
Fix this by adding the directories where the QGIS libraries reside to search path of the dynamic linker:
on Linux: export LD_LIBRARY_PATH=/qgispath/lib
on Windows: set PATH=C:\qgispath;%PATH%
These commands can be put into a bootstrap script that will take care of the startup. When deploying custom applications using PyQGIS, there are usually two possibilities:
require user to install QGIS on his platform prior to installing your application. The application installer should look for default locations of QGIS libraries and allow user to set the path if not found. This approach has the advantage of being simpler, however it requires user to do more steps.
package QGIS together with your application. Releasing the application may be more challenging and the package will be larger, but the user will be saved from the burden of downloading and installing additional pieces of software.
The two deployment models can be mixed - deploy standalone application on Windows and Mac OS X, for Linux leave the installation of QGIS up to user and his package manager.
Finally got it working. Had to completely wipe and reinstall QGIS twice and separately remove python-qgis. Also had to uninstall anaconda. After the second fresh install of QGIS I've gotten it working.
No other changes to my configuration.
I'm trying to follow this tutorial and I'm getting the following error:
ImportError: No module named django.core.management
I'm completely new to python. I believe Visual studio is using a version of python I already had installed in c:\Python27, could that be causing a problem?
Someone mentioned in a link I found that they had to copy the 'django' folder to the project folder, but I don't know where that would be. I don't even know what the error means really unless there's a missing package (like dll or assembly in .NET?), but I don't know what paths python would use to try to find a package or even what one would look like.
I see there's a PYTHONPATH environment variable that I don't have declared, should I declare that? Should it point to the C:\Python27 directory?
First, do you have checked your "Python Environment" in your project folder? It may seems like...
Here you may find your django with version. If you dont find it then compile setup.py from django folder again with desire python version. And then right click on "Python Environments" from your project and click on "Add/Remove Python Environments" to select python version.
Ok with a lot of fooling around I found this directory:
%LOCALAPPDATA%\Microsoft\Web Platform Installer\installers\PythonDetectInstalls
In a mangled sub-folder there is a powershell script DetectPythonInistalls.ps1 that has these two lines for checking if python is installed already:
$regKey = "hklm:SOFTWARE\Python\PythonCore\$pythonVersion\InstallPath";
$correctRegKey = "hklm:SOFTWARE\Wow6432Node\Python\PythonCore\$pythonVersion\InstallPath";
Uninstalling all my pythons did not remove these keys. After removing these registry keys with regedit, WPI allowed me to install its own version of python 2.7 and all the other goodies to go with the Windows Azure Python SDK and it worked.
Disclaimer of research:
I have examined the following other StackOverflow questions:
How to import numpy in python shell
How can I use numpy without installing it?
Import a module from a relative path
Perhaps to some, those may answer my question, but according to my knowledge, I still do not understand the situation.
I am trying to import numpy so that matplotlib will work, but upon execution of the __init__.py file in the numpy folder, the following error message is displayed:
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
Explain what it means to import something from its source directory as opposed to some other way of importing it. Does it mean that it should not be source code when it is imported? Or does it mean that it literally is just the wrong directory/folder that I am importing. I know that one other StackOverflow answer is:
The message is fairly self-explanatory; your working directory should not be the numpy source directory when you invoke Python; numpy should be installed and your working directory should be anything but the directory where it lives.
However, I don't understand this. Aren't you supposed to import things that you want to work with? I'm assuming that the import command combines the source directory into your current working directory in this statement.
I also read the other answers such as:
Using distutils to install local directories
Using virtualenv to create a virtual system directory
Using Enthought's EPD to have numpy pre-installed in what I believe to be the system directory,
and
Using a command like $ dpkg -i --force-not-root --root=$HOME mypackagename.deb to create what I believe is some kind of sub-system directory that is treated like a system directory.
So, correct me if I'm wrong, but does numpy somehow strongly require to be somehow installed in the main system directory?
Machine status:
I am using Windows machines without administrative privlidges.
They have Python 3.3 Shell as well as matplotlib installed.
When running command prompt, python and python3 are not recognized. I have to run the Python shell from the applications menu.
I can successfull begin importing matplotlib from even my own directory, different from theirs, but it stops upon reaching __init__.py of the numpy module, if it exists and reports the error stated above.
Update:
Luckily, my administrators were able to directly install numpy correctly in the site-packages folder. Thank you for answering my question though. I understand the situation a lot more because of you.
numpy includes extension modules written in C. You will need to build these extension modules before the numpy package is complete. The most robust way to do this is to build it and install it to site-packages like normal. You can also install it to another directory using the standard distutils options for this. However, once you have installed it, you should change your directory out of the source tree. Python starts looking for packages in your current directory, so the presence of the incomplete numpy package (without the necessary built C extension modules) will be picked up first and lead to the error that message that you quote. This happens a lot, so we give a long message explaining what to do.
I'm trying to get a Python package to install to my home directory because I don't have the privileges to install it system-wide.
The package is PyProj, and I am trying to install it using python setup.py install --home=~ (with Python 2.4.3), as recommended in the Python documentation. The package compiles successfully and copies itself to what I assume are the correct directories (the directory ~/lib64/python/pyproj appears during install).
But, when I load Python up and type import pyproj, I'm told ImportError: No module named pyproj.
Any thoughts on what might be going on?
You'll need to set PYTHONPATH to tell Python where to locate your locally installed packages.
For example:
[you#home]$ export PYTHONPATH="~/lib64/python"
Or, to do this within the interpreter (or script):
import sys, os
sys.path.append(os.path.expanduser("~/lib64/python"))
For more information on how Python locates installed modules, see section on The Module search Path in docs.
~/lib64/python/pyproj is not part of your PYTHONPATH. There are two or three ways around this, depending on your needs.
The first is to directly modify the path in your module, suitable if you're only going to use it from one module. As noted in the comments, this method does not do expansion on the '~' character.
import sys
sys.path.append('/home/username/lib64/python')
import pyproj
The second way is to add ~/lib64/python/pyproj to your system's PYTHONPATH, through whatever method your system suggests. A line in .bash_profile is shown below.
export PYTHONPATH=$PYTHONPATH:~/lib64/python/pyproj
See the Python Documentation for more details.