I am trying to install vtk for python 2.7 for Windows 64 bit PC
C:\Users\Abhi>conda install vtk
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
Where as
C:\Users\Abhi>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named vtk
>>>
for pip also I've tried
C:\Users\Abhi>pip install vtk
Collecting vtk
ERROR: Could not find a version that satisfies the requirement vtk
(from versions: none) ERROR: No matching distribution found for vtk
I've tried installing from executable file https://vtk.org/download/
Any help would be appreciated
Thanks
Abhishek
It sounds like you may be installing VTK for a python environment, but then using another one when you try importing it. It's important to keep track of which python you are using when performing an install.
The way I keep things organized is to create conda environments. If I were you, I would do the following:
Create a conda environment (you can specify any version of python you want)
conda create -n myenv python=3.4
Now, you've created an environment in which you can install packages for your own python project. You can create other environments with different packages and versions for other python projects using this command. Next, make sure to activate your conda environment (you must do this every time you start a new session)
conda activate myenv
Now, after activating your environment, make sure that your environment is indeed active by running
conda info --envs
The active environment will have a * next to it. Make sure that the * is next to "myenv", not base.
After making sure you are indeed in your active environment, install all packages you need (including VTK). Here's how to install vtk:
conda install -c anaconda vtk
After you're done installing packages, you can make sure they are installed in your environment by running
conda list
Scroll down until you see your package.
Now, you should be able to run python scripts with the packages you installed. Test things out by running your import vtk line and let us know if things worked.
Related
After creating and activating a virtual environment:
python3 -m venv env
. ./env/bin/activate
the global /usr/bin/pip3 does not install a package globally. Actually it does copy package files but package is not fully installed:
/usr/bin/pip3 install docker
Collecting docker
Downloading docker-5.0.3-py2.py3-none-any.whl (146 kB)
|████████████████████████████████| 146 kB 2.5 MB/s
Requirement already satisfied: requests!=2.18.0,>=2.14.2 in /usr/lib/python3/dist-packages (from docker) (2.22.0)
Collecting websocket-client>=0.32.0
Downloading websocket_client-1.2.1-py2.py3-none-any.whl (52 kB)
|████████████████████████████████| 52 kB 2.9 MB/s
Installing collected packages: websocket-client, docker
Successfully installed docker-5.0.3 websocket-client-1.2.1
Files are placed globally:
ls /usr/lib/python3.8/site-packages
docker docker-5.0.3.dist-info websocket websocket_client-1.2.1.dist-info
But neither a shell without venv active doesn't consider docker as installed:
pip3 list|grep docker
python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'docker'
>>>
nor the venv sees docker package as installed:
(env) pip3 list|grep docker
(env) python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'docker'
>>>
Is this a bug?
How can I install a package globally with pip3 while a venv is active?
Why do I want to do this?
Ansible is launched from a venv and it targets the localhost. So if I'm using just pip3 as an executable, it uses the binary from the venv. If I'm using /usr/bin/pip3 I get the above behavior.
It's a more complex open source project and I don't have the option to not run Ansible from a venv or not to target localhost.
Thanks
I don't use venv myself, but the whole point of virtual environments is having a set of files separated from the rest of the system.
If you create a virtual environment and are inside of it you shouldn't be using /usr/bin/pip3, you should be using the default pip3, since those two versions might not even be compatible with each other.~
It's a more complex open source project and I don't have the option to not run Ansible from a venv
You always have the option of running something inside a virtual environment, it might happen that the program does not respect that and use global paths and ignore that virtual environment, which shouldn't be happening.
From the venv docs:
Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories
This means that you should create your virtual environment, activate it, install whatever you want inside of it, and then run everything inside that virtual environment.
So I don't see this as a bug, it just seems like you are not using as it is intended to be used. If you want something installed globally, why are you using a virtual environment in the first place?
I am trying to install dbus on Anaconda python environment and I am struggling.
Here is the error message I am getting:
e#gateway:~$ python
Python 3.5.4 |Anaconda custom (64-bit)| (default, Oct 13 2017, 11:22:58)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/e/anaconda3/lib/python3.5/site-packages/dbus/__init__.py", line 77, in <module>
import dbus.types as types
File "/home/e/anaconda3/lib/python3.5/site-packages/dbus/types.py", line 6, in <module>
from _dbus_bindings import (
ImportError: /home/e/anaconda3/lib/python3.5/site-packages/_dbus_bindings.so: undefined symbol: _Py_ZeroStruct
>>>
Here are some of the outputs I think may be asked:
e#gateway:~$ conda install dbus
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /home/e/anaconda3:
#
dbus 1.10.22 h3b5a359_0
e#gateway:~$ sudo apt-get install libdbus-glib-1-dev libdbus-1-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libdbus-glib-1-dev is already the newest version (0.106-1).
libdbus-1-dev is already the newest version (1.10.6-1ubuntu3.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
e#gateway:~$ sudo apt-get install dbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
dbus is already the newest version (1.10.6-1ubuntu3.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
e#gateway:~$ which python
/home/e/anaconda3/bin/python
e#gateway:~$ conda --version
conda 4.3.31
e#gateway:~$ sudo /home/e/anaconda3/bin/python -m pip install dbus-python
The directory '/home/e/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/e/.cache/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.
Requirement already satisfied: dbus-python in ./anaconda3/lib/python3.5/site-packages
DBus is working fine on the system python, however not working on Anaconda Python.
Python 2.7:
e#gateway:~$ which python
/usr/bin/python
e#gateway:~$ python
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>>
Python 3.5:
e#gateway:~$ which python3
/usr/bin/python3
e#gateway:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>>
Can anyone help me? Am I missing something blatantly obvious here?
Thanks in advance.
I had similar issues, there are few cases where dbus and python don't work well out-of-the-box. The consensus appears to be that you need a system-level install (i.e. apt-get) to get dbus to work. I believe the /home/e/anaconda3/lib/python3.5/site-packages/_dbus_bindings.so: undefined symbol: _Py_ZeroStruct error you're seeing is directly related to that.
conda install dbus does not add anything to ~/anaconda3/lib/python3.6/site-packages, but instead appears to install some executables in ~/anaconda3/bin/ like dbus-run-session, dbus-daemon, etc. This makes some sense when you analyze the contents of the dbus tarball https://anaconda.org/conda-forge/dbus, as it's all C files and executables. I'm not sure it's supposed to be the dbus python module, but I could be wrong.
EDIT:
I searched the conda repositories and found a few individuals that uploaded a version of dbus-python, presumably that they compiled and installed. I tried this one out in a py3.6 conda environment via:
conda install -c scottwales dbus-python
I was then able to import dbus. This is a hacky approach and should not be used in production, I'd recommend listening to
Carlos Cordoba's post below. But if you need a solution now, search through some user conda packages or try to compile the library yourself.
Can anyone help me? Am I missing something blatantly obvious here?
Yes, you are. There's one thing people still don't understand about conda: conda is not a pip replacement. It is a general package manager, in the same vein as apt-get, yum, brew, emerge, etc, but cross-platform and based on Python.
In this case, that means that conda install dbus does not install the Python Dbus bindings, as you would expect with pip . It installs the Dbus C package itself, which is needed by Qt 5 (again, the C++ library, not the Python bindings to it).
Unfortunately, there are no Conda packages for dbus-python. To make matters worse, it seems there's no easy way to create packages for it, as pointed out here.
Finally, you said
Here is the error message I am getting
The (most probable) cause of that error is because you added your system Python dist-packages path to the PYTHONPATH of Anaconda or because you blindly copied the dbus module from system Python to Anaconda. Please don't do that ever again. System Python and Anaconda packages are compiled with different compilers and under different conditions. So mixing them is the cause of incomprehensible errors, just like the one you reported.
I've been having difficulty with Python recently, mainly since I think I had several versions and conflicts (due to Anaconda installs, canopy installs etc.). So I cleaned those out.
I reinstalled python (2.7) via brew.
I reinstalled numpy and matplotlib via pip.
I also reinstalled astropy and h5py via pip.
However, I get a clean import of numpy and matplotlib, but not of astropy and h5py:
~ > python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>> import astropy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named astropy
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named h5py
>>>
My suspicion is that your pip executable is not linked to your python executable, which means when you run pip install astropy it is installing it in the site-packages for a different python.
One way to make sure you're using the correct pip is to not use
$ pip install astropy
but instead use
$ python -m pip install astropy
If this fails, it probably means that you don't have pip installed for the python instance you're using, and you need to install it (note that for Python 2 version 2.7.9 or later, or Python 3 version 3.4 or later, pip comes bundled with Python).
If this still doesn't work, then something stranger is going on. It may be due to having $PYTHONPATH or $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH set in a way that interferes with your python imports. In this case, you could clear these variables and try again. Otherwise, I'd consider using a package bundle such as conda or canopy. It makes these kinds of installation issues much smoother.
Edit: I see now that you've used conda and canopy, and you suspect these were causing your problems. Conda and canopy, by design, both sandbox their python installations so that they shouldn't get interference from other installs in your system, unless you force such interference by setting the environment variables I mentioned above. I'd suggest reinstalling conda and wiping those environment variables from your bash/csh startup script.
I am trying to install scrapy and for that I have installed python 2.7 and conda(as pip was giving me errors that i couldn't solve.) after that I created a separate environment for scrapy named py2 with conda.
With this output I suppose that scrapy is installed successfully on my machine.
[py2] C:\Users\ADMIN>conda install -c https://conda.anaconda.org/scrapinghub scrapy
Fetching package metadata: ......
Solving package specifications: ...........................
# All requested packages already installed.
# packages in environment at C:\dev\Anaconda3\envs\py2:
#
scrapy 1.0.3 py27_2 scrapinghub
Now I make it sure that it is python 2.7 I executed this
[py2] C:\Users\ADMIN>py
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Which is also correct I suppose.
Now still I am unable to do this
>>> import scrapy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scrapy
which indicates that scrapy is not installed.
Environment : Windows 8 (64 bit)
I am a beginner both in python and scrapy.
There are interestingly a few hacks that are needed to run Scrapy on Windows.
You would need to install unofficial support for Windows in Python, look for PyWin32 section:
http://www.lfd.uci.edu/~gohlke/pythonlibs/ Afterwards remember to run postinstall.py -install as advised on this page.
Depending how you are setup, you might need to install C++ compiler for Python, required to run lxml:
https://www.microsoft.com/en-us/download/details.aspx?id=44266
Please look for similar questions referring to overall Python not only Scrapy e.g. error: Unable to find vcvarsall.bat Depending on how you are setup you will find hints around.
As it was all in virtual environment of conda, while installing scrapy I needed to pass the name of conda virtual environment, except that scrapy would have been installed in the root(I mean outside the environment or for the machine.)
So for py2 virtual environment, after activating this, following command will install scrapy:
conda install -n py2 -c https://conda.anaconda.org/scrapinghub scrapy
Here py2 is environment's name.
This page helped me to figure out what was happening here.
I must say python is not that easy to learn.
Attempting to finally make the jump to Python 3, but am running into some issues with virtualenvwrapper. I start out by creating the virtual environment like so:
mkvirtualenv -p /usr/local/bin/python3 projectname
which yields:
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3'
New python executable in projectname/bin/python3.3
Also creating executable in projectname/bin/python
Installing setuptools, pip...done.
So far, so good. I check the python console to make sure that the environment is looking at the correct interpreter and all that and it is. Here's where sadness happens (while the virtualenv is active):
pip install flask claims to be successful, but alas:
Python 3.3.3 (default, Jan 2 2014, 13:26:32)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'flask'
Here's the issue:
$ pip show flask
---
Name: Flask
Version: 0.10.1
Location: /usr/local/lib/python3.3/site-packages
Requires: Werkzeug, Jinja2, itsdangerous
Unless I'm completely misunderstanding virtualenv/wrapper and their respective magics (which I very well could be), it seems like pip install is installing Flask globally rather than to the site-packages within my virtualenv, and thus the virtualenv is ignoring it.
Any clues what's going on here/how to fix? Am I wrong in assuming that virtualenvwrapper is ready for primetime with python3? Pretty solutions where I don't have to mangle my .bashrc or manually set environment variables are preferable. I'm hoping there's a way to do this through the api's provided by virtualenv and virtualenvwrapper.
Thanks!
I had problems with pip installing packages globally instead of in the activated virtualenv too. Have a look at pip installing in global site-packages instead of virtualenv for the question (and the answer).
Basically, the solution consisted of modifying the shebang of the pip scripts within the virtualenv as they pointed to the wrong python installation (global instead of in the virtualenv). Just change the shebang to point to the correct location and you're set.
Note: credit should go to Chase Ries who came up with the solution.
I had the same issue. It appears to be resolved as of Virtualenv 1.11.4.