How do I examine if I have properly installed pymunk - pymunk

I typed "python3 install pymunk" in terminal and seems that it is installed. But how do I, in terminal, examine it is properly installed? I tried to type "import pymunk" in terminal, yet it says
-bash: import: command not found
When I run pymunk in sublime, it says
Loading chipmunk for Darwin (64bit) [/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymunk/libchipmunk.dylib]

You need to do the import pymunk from inside the python interpreter, or inside a python file that you run.
So, first you start the python interpretee with python3 when you are in the terminal and then you can do the import pymunk when you are inside python.
Pymunk in a python library, and usually you import the libraries from inside python. If you are a beginner I think it would be good for you to read a beginners guide to python, for example http://inventwithpython.com or some other intro.

Related

How to execute the right Python to import the installed tensorflow.transform package?

The version of my Python is 2.7.13.
I run the following in Jupyter Notebook.
Firstly, I installed the packages
%%bash
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.15.0 apache-beam[gcp]
Then,
%%bash
pip freeze | grep -e 'flow\|beam'
I can see that the package tensorflow-transform is installed.
apache-beam==2.19.0
tensorflow==2.1.0
tensorflow-datasets==1.2.0
tensorflow-estimator==2.1.0
tensorflow-hub==0.6.0
tensorflow-io==0.8.1
tensorflow-metadata==0.15.2
tensorflow-probability==0.8.0
tensorflow-serving-api==2.1.0
tensorflow-transform==0.15.0
However when I tried to import it, there are warning and error.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py:12: The name tf.estimator.inputs is deprecated. Please use tf.compat.v1.estimator.inputs instead.
ImportErrorTraceback (most recent call last)
<ipython-input-3-26a4792d0a76> in <module>()
1 import tensorflow as tf
----> 2 import tensorflow_transform as tft
3 import shutil
4 print(tf.__version__)
ImportError: No module named tensorflow_transform
After some investigation, I think I have some ideas of the problem.
I run this:
%%bash
pip show tensorflow_transform| grep Location
This is the output
Location: /home/jupyter/.local/lib/python3.5/site-packages
I tried to modify the $PATH by adding /home/jupyter/.local/lib/python3.5/site-packages to the beginning of $PATH. However, I still failed to import tensorflow_transform.
Based on the above and the following information, I think, when I ran the import command, it executes Python 2.7, not Python 3.5
import sys
print('\n'.join(sys.path))
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/IPython/extensions
/home/jupyter/.ipython
Also,
import sys
sys.executable
'/usr/bin/python2'
I think the problem is tensorflow_transform package was installed in /home/jupyter/.local/lib/python3.5/site-packages. But when I run "Import", it goes to /usr/local/lib/python2.7/dist-packages to search for the package, rather than /home/jupyter/.local/lib/python3.5/site-packages, so even updating $PATH does not help. Am I right?
I tried to upgrade my python, but
%%bash
pip install upgrade python
Defaulting to user installation because normal site-packages is not writeable
Then, I added --user. It seems that the python is not really upgraded.
%%bash
pip install --user upgrade python
%%bash
python -V
Python 2.7.13
Any solution?
It seems to me that your jupyter notebook is not using the right python environment.
Perhaps, you installed the package under version 3.5,
but the Notebook uses the other one, thus it cannot find the library
You can pick the other interpreter by clicking on: Python(your version) - bottom left.
VS-Code - Select Python Environment 1
However you can do this also via:
CNTRL+SHIFT+P > Select Python Interpreter to start Jupyter Server
If that does not work make sure that the package you are trying to import is installed under the correct python environment.
If not open up a terminal, activate the environment and install it using:
pip install packagename
For example i did the same thing here: (Note: I'm using Anaconda)
installing tensorflow_transform
After a installation, you can import it in your code directly like this:
importing tensorflow_transform

Spyder not showing stderr output in IPython console when running commands with os.system

Setup: MacOS High Sierra, Spyder 3.3.1, Python 2.7.15 64bits, Qt 5.9.4, PyQt5 5.9.2 on Darwin
I run the following code in the IPython console within Spyder:
In [1]: import os
In [2]: os.system("ls")
Out[2]: 0
In [3]: os.system("aasdasd")
Out[3]: 32512
I can see the output to stdout of the ls command in the bash shell where I run spyder, but not to stderr of the second os.system call that should print sh: asdasd: command not found.
Where does spyder redirect stderr to? Is there a way to see error messages like the one generated in the second case?
Thank you very much!
(Spyder maintainer here) This was fixed in spyder-kernels 0.3.0, the package that provides kernels for our consoles. And by fixed I mean that both stdout and stderr of external commands are now shown directly in our IPython consoles.
To update spyder-kernels, please close Spyder and run in a system terminal (xterm or Terminal.app, this doesn't work on Windows):
conda install spyder-kernels=0.*
if you use Anaconda (it's not available at the moment, but it should be shortly, please wait until it is), or
pip install spyder-kernels==0.*
if you use a custom Python installation.

how to import h5py on datalab?

Does anybody know how to install h5py on datalab? pip install h5py doesn't work. apt-get install python-h5py is working in the shell but it doesn't recognize the package in datalab notebook!
Thnaks
It is true that !pip install h5py wil allow you to install the library but unfortunately, even after a successful installation, the import will fail:
The issue is rooted on an ongoing python-future issue ("surrogateescape handler broken when encountering UnicodeEncodeError") that is experienced in datalab because the underlying OS uses an 'ANSI_X3.4-1968' file system encoding.
As a hacky workaround, you may remove line 60 from h5py's __init__.py by running the following command from within a notebook cell:
!sed -i.bak '/run_tests/d' /usr/local/lib/python2.7/dist-packages/h5py/__init__.py
Just make sure you run it using bash syntax: !pip install h5py in any notebook cell.

anaconda packages installed but not found

I have a new macbook air running yosemite and I have installed Anaconda.
I want to practise on making GUIs with either wxpython.
When I run " conda list" wxpython is there, but when I import it I get "No module named wxpython" .
Any ideas how to fix this? Anaconda is added to my path in the bash_profile.
Regards
According to this it looks like the correct way to import this package is import wx. Try that.
It's possible you might run into a cairo error like this:
ImportError: /usr/lib64/libpangocairo-1.0.so.0: undefined symbol: cairo_ft_font_options_substitute. I was able to get around this by installing the cairo package via conda install -c https://conda.anaconda.org/pmuller cairo.

Install BeautifulSoup, mrjob, pattern, and seaborn on python 2.7 on Jupyter

I am learning how to use the new Jupyter. I want to install packages:BeautifulSoup, mrjob, pattern, and seaborn on python 2.7. I first tried to do so by running pip install BeautifulSoup mrjob pattern seaborn That all returns: SyntaxError: invalid syntax
I also tried from bs4 import BeautifulSoup, it did work for Beautifulsoup. But I still don't know how to install other packages.
Wondering anyone know why there was syntax error for using pip install? Is that because I haven't installed pip on python 2.7?
I was also able to install these packages from iphython notebook window by running
import pip
def install(package):
pip.main(['install', package])
install('BeautifulSoup4')
Have you tried installing one package at a time. This helps you find which installation command not working.
You can find Julia packages here.
The problem was I was running pip from inside Jupyter. However, Jupyter is a command line program. Thanks to Mwaskom, the solution is run it from a terminal using:
pip install BeautifulSoup mrjob pattern seaborn
You could try:
!pip install BeautifulSoup mrjob pattern seaborn