Unable to imoprt modules on python script while running on cmd - windows

I can not run python scripts on Command Prompt which has to import any module whereas I can run that script without any error on python IDLE. I think, this is happening after I install Anaconda on my machine.
Even if I run "Python" command it starts the shell and then there I can import any module that I want without any error.
C:\Users\USER>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
>>>
But when I try to run a script which has to import any module directly It rises a "ModuleNotFoundError" error.
E:\Python\PyQt4\Apps\test>main.py
Traceback (most recent call last):
File "E:\Python\PyQt4\Apps\test\main.py", line 9, in <module>
from PyQt4 import QtCore, QtGui
ModuleNotFoundError: No module named 'PyQt4'
E:\Python\PyQt4\Apps\test>
I don't know why it is happening

Related

Import Bio module from Bash

I'm working on a remote server with Linux.
I created a new environment and got biopython installed with conda:
conda create --name new_bio python=3.5
conda activate new_bio
conda install -c conda-forge biopython
import Bio works when I am running it inside python:
(new_bio) -bash-4.2$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bio
>>> exit()
import Bio works when I am running my script like this:
(new_bio) -bash-4.2$ python my_Bio_script.py
hello
my_Bio_script.py:
from Bio import SeqIO
print('hello')
But when I try to run my script with Bash :
(new_bio) -bash-4.2$ sbash my_bash.sh
my_bash.sh bash file:
#!/bin/bash
module load anaconda ### load anaconda module
source activate new_bio ### activating environment, environment
must be configured before running the job
python my_Bio_script.py
I get this error:
Traceback (most recent call last):
File "T.py", line 1, in <module>
from Bio import SeqIO
ModuleNotFoundError: No module named 'Bio'
I have to send it as a Slurm Job in a bash file.. what can I do?
One potential way to start debugging is to print environment variables PYTHONPATH and PATH.
What I would recommend is, print $PATH and $PYTHONPATH. Analyse the python version and path, replicate the same inside the bash script.
Also, analyse the ~/.profile as well as ~/.bashrc file and see whether there is any discrepancy with PATHs for python.

Python 3.6 - Tensorflow DLL load failed when importing tensorflow

I installed Tensorflow on my command prompt using pip3 on Python 3.6 using:
pip3 install tensorflow==1.5
When checking if I could import tensorflow off the terminal using Python I got the following error message:
Python 3.6.0rc2 (v3.6.0rc2:800a67f7806d, Dec 16 2016, 23:22:07) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
What exactly is missing from the DLL?
Are there any issues when installing? Also, why are you installing tensorflow 1.5 when 1.9 is available? I would first try pip uninstall tensorflow and then pip install tensorflow. If you still have issues I would try going here to download the .whl file and then you can do pip install [whatever the filename is].whl. Directly installing these .whl files has solved many a problem for me.
To answer your question, it looks like you are missing descriptor.py from google protobuf. You could try downloading that and moving descriptor.py directly, but my guess is if it can't find one file it's probably missing other things as well.
Looking at other problems with tensorflow imports, it looks like the problem is compatibility with python 3.6 having a divergent path with pip, however it looks like this was solved at some point in the last year. If you're still stuck, of course try upgrading pip, python, and tensorflow; then try downgrading to python 3.5 to see if that works. Best of luck!
Change the protobuf version to pip install protobuf==3.6.0

Tensorflow install on Windows with anaconda and no internet connection

I can not install Tensorflow on Windows because there in no internet connection based on commpany's security policy.
I just installed anaconda and python by transmiting files with intranet.
Please let me know how to install that with no internet connection.
==========================================================================
In addition, when I used the below command after installing tensorflow, I found
other problems..
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Daisy\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\Daisy\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 63, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\Daisy\Anaconda3\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
ImportError: No module named 'google'
I don't know how to solve this one.
If you can download the whl file and transfer it to your workstation, then you can run:
pip.exe install --upgrade --no-deps <tensorflow whl file name>
This should avoid trying to connect to download tensorflow dependencies, as anaconda already has most of these.

urllib.request not found in .py code

I'm working with Python 3.4 on Windows:
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
At the Python command line, everything works fine (no errors):
>>> import urllib.request
>>>
Then I write the following single-line code test.py:
import urllib.request
If I execute test.py I get:
Traceback (most recent call last):
File "Z:\user\test.py", line 1, in <module>
import urllib.request
ImportError: No module named request
I tried various things (obviously unsuccessfully!), so I'm absolutely baffled. Can anyone give me a clue??...
Make sure that you run the script using Python 3 interpreter e.g., configure your system to use Python launcher py and add the appropriate shebang (#!/usr/bin/env python3) in your Python script.

Unable to import argparse 1.2.1 for python 2.5 on windows

So, I thought that I had correctly installed the setuptools and argparse 1.2.1.
C:\Python25_64bit>python ez_setup.py argparse
Searching for argparse
Best match: argparse 1.2.1
Processing argparse-1.2.1-py2.5.egg
argparse 1.2.1 is already the active version in easy-install.pth
Using c:\python25_64bit\lib\site-packages\argparse-1.2.1-py2.5.egg
Processing dependencies for argparse
Finished processing dependencies for argparse
C:\Python25_64bit>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:19:34) [MSC v.1400 64 bit (AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named argparse
>>> quit()
However, it seems that I can't import it, as you can see above. I also tried directly adding the egg to my Eclipse PyDev projects, but this was to no avail, either. As you can see, nothing is set in my environment. Perhaps, this is the problem?
C:\Python25_64bit>echo %PYTHONPATH%
%PYTHONPATH%
C:\Python25_64bit>echo %PYTHONHOME%
%PYTHONHOME%
I hope you paid attention while installing and noted where argparse was installed.
In your script (run from the commandline or from your IDE) include at the top:
import sys
for p in sys.path:
print repr(p)
to see all the paths python is searching through. Either add the path to argparse using:
sys.path.insert(0, '/your/path/to/argparse')
or move the install to something in the path.
The environment variables can be empty, there are compiled in elements for sys.path as well.

Resources