Python module installed on Windows 10 with Ubuntu bash is not recognized - python

I have to use TensorFlow on my Windows 10 laptop, on which I have installed python 2.7, 3.2 and 3.4.2. I followed the instructions on the first answer here. I managed to install pip3 and tensorflow with the Ubuntu bash environment and I successfully tested TensorFlow on the command prompt. However, when I try to import it in my IEP environment (using Python 3.4), the module is not recognized. I am pretty new in managing python modules. What am I missing?
UPDATE: I found out that, when using Python via the ubuntu bash, the version is 3.4.3, but I never installed this version. Is there a way I can make it work with the versions I installed?

Looks like you are trying to make things complex to start with and having 3 (actually 4) python environment is making it even more harder if you are new to python. If you want to start using TF quickly and avoid platform specific problem, the quick route will be to remove most of platform 3.x installs and keep one if you really need 3.x otherwise you can do a lot with python 2.7. Once you have only 1 python environment, it will be very easy for you to manage and run faster. If you don't want to change anything and get you going with python do the following:
Install pip 8.1 or above
Install virtualenv for python 2.7 using pip - (This will help you to keep all the python specific modules within a specific folder)
Install TF for python 2.7 from https://www.tensorflow.org/get_started/os_setup
Use python 2.7 shell
If you run this command it will show which TF module you are using and where it is install (you must have TF installed):
python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'

Related

After switching to Python 3.6.5_1, the displayed version is still 3.7.2

I am trying to use Python 3.6.5_1 for OpenCV, so I have switched Python versions using "brew switch python 3.6.5_1", but after checking my current version of Python using "python --version", I apparently am still using Python version 3.7.2. Any solutions? By the way, this is the tutorial I am following: https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/
Check your python path to see where your python executable is being stored---which python in terminal. I bet it's still pointing to your 3.7.2 directory's python.
If you are switching between python versions, virtualenv can be used to initialize isolated environment with a specific python version.
virtualenv -p [preferred-python-version] open_cv_project_env

Three versions of Python?

In case it is relevant, I am using Ubuntu 16.04 LTS. I went to install some software (Jupyter Notebook) which uses Python, and the recommendation was to either use python3 install if I have Python 3, or python install if I am still using 2.7.
My Ubuntu installation came with both. python --version returns 2.7.12 and python3 --version returns 3.5.2. However I also know that there is currently a Python 3.6 out there, which I installed... but it appears to use its own special reference python3.6 --version which returns 3.6.4, whereas I had expected it to upgrade/replace python3 so doing python3 --version would return 3.6.4, but nope.
I'm not sure what the correct approach is here because apparently I shouldn't be messing with the Python versions that come installed since the OS may rely on them. At the same time it seems strange to install software that calls for Python3 even though it's going to be using 3.5 rather than 3.6.
Am I overthinking this? Is it expected behavior to use python3.6 specifically for 3.6-related features? Or do most people re-alias python3 to redirect to python3.6 instead? What about pip? pip3? Is there a pip3.6? I'm not entirely certain how I should be thinking about all these different Python installations.
You may want to use virtualenv so you can control your python environment, it's good practice. With virtualenv you can specify which version to use and your libraries are installed only for the project that needs it.
You can use python2 and python3 alongside just fine. However, if you want to use different minor versions of the python, for example 3.4 and 3.6, you have to set up virtual environment for each version. Look for the virtualenv or other solution.

Is there any possibile issue in having Anaconda Python 3.6 as default Python version in macOS?

I've just installed Anaconda on my macOS machine and it has changed my PATH so that now Python 3.6 is the default version (i.e. the Python 3.6 interpreter opens when I type python in the Terminal). I'm fine with this since this is the version I usually use, but I was wondering if there is the possibility of this messing up with the system functionalities relying on having 2.7 as default. I suppose that there will no problems since 2.7 is still in /usr/bin, but I would like to be sure.
I have been using Anaconda Python.
I had a problem with the default Python installed on my Mac OSX 10.11 at one point, because of the numpy package.
It was a problem for me when I tried to run a script in Anaconda Python which relies on a numpy version higher the Mac default version and I wasn't able to get it working using conda install, pip install, or by changing the PATH/PYTHONPATH.
I was able to install the package but Anaconda Python would not recognize the new version.
I ended up removing the entire numpy that came with the Mac. But I do not think this would be a problem in the other way (i.e., using mostly the Mac python but occasionally install other packages for Anaconda Python) because the default Python does not look at the Ancondoa package directory.

ImportError when changing Python interpreter

I have been using PyCharm on Ubuntu to run some Python code, where in Edit Configurations I specified the interpreter path as /usr/bin/python2.7. The code uses the pygame module, and so to install this, I also ran sudo pip install pygame. Then I used import pygame in my Python script, and the file ran ok.
However, I now want to use Python 3.4. So, in PyCharm, I specified the interpreter path to be /usr/bin/python3.4. However, when I run the same file, I now get the error: ImportError: No module named 'pygame'.
Can somebody explain why this is happening? How can I get my Python 3.4 interpreter to find Pygame?
Thanks!
Each python installation has a separate set of libraries. Your python 3 does not know about Python 2 and its libraries. It seems the default pip command calls the python2 pip script. Run again the pip install, but with the python3 pip (look for it in your python3 folder, it is probably named pip3)
As others have pointed out, different Python installations will maintain their own independent set of libraries. Bear in mind that you can install packages from the same window that you use to change the interpreter in PyCharm for a project. You might find that more convenient if you're switching between interpreters.
You just click the green 'plus' icon to do so:
pygame has different releases for each version of Python.
As you have the Python 2.7 module and want to upgrade to Python 3.4, you'll need to reinstall pygame using Python 3.4 instead, you can using pip again or you can download files from here: http://www.pygame.org/download.shtml.

ipython using 2.6 version instead of 2.7

I am trying to set up iPython to use 2.6 version instead of 2.7. Is there a way to do it?
More information.
I am trying to set up a iPython notebook to develop Spark application, however, the python version across the whole cluster is 2.6 where only the name node has the latest Anaconda python version installed 2.7. In that case, when I started a python notebook, it will use 2.7 as the interpreter and I am running into errors when I tried to distribute the work.
Instead of upgrading the wholecluster to use 2.7, I prefer downgrade the iPython version on the name node to be 2.6, is there a way to do it?
Update:
Thanks for the suggestion from Jivan, it is actually fairly easy to use python virtualenv to install the older version of iPython inside the virtual environment, whenever you want to use it, you can have a bash script looks like this and there will be a proper iPython notebook environment that has the python version consistent across the cluster.
#!/bin/bash
which python
source /root/user/python-ev/bin/activate
which python
ipython notebook --profile=pyspark
iPython 1.0 is the last main version of iPython to support Python < 2.7 interpreter.
So you need to install iPython 1.2.1 at most, if that's not done already.
Now to associate it to Python2.6:
$ sudo python2.6 setup.py install
More information on this link. The author skipped the part about which version of iPython to use because at this time all versions of iPython supported Python < 2.7.
It could work, but it's not certain because it depends on your existing config, etc.
If it doesn't, a different way (a bit hacky however) could be found here.

Categories