No module named ib.message - python

I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message

I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.

Related

No module named 'postal' python error on Apache2

I followed the instructions and successfully installed pypostal python package (package to help parse addresses) https://github.com/openvenues/pypostal.
I'm trying to set this up so the python script can be callable through an apache server on an ubuntu box. It works fine when executing the script from Terminal. However, it doesn't work when I make a call to apache to execute the script and I get the following error in the apache logs. I believe it might be some pathing issue but I haven't had much luck to resolve it. Any ideas will be appreciated.
Error:
File "/var/www/html/cgi-bin/get_parsedAddress.py", line 5, in
from postal.parser import parse_address
ModuleNotFoundError: No module named 'postal'
python script contents:
import sys
from postal.parser import parse_address
addressList = parse_address(sys.argv[1])
print(addressList)

ImportError, no module named

I get ImportError: no module named Flopy when I try to run the following script from an Anaconda prompt in the folder that the script it stored in, but when I run the script through Spyder it imports Flopy just fine and the rest of the code (not shown) which uses Flopy also works.
# import the required libraries
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
The Spyder ran version never runs the code under than 'except' section since it managed to import Flopy at first try. I tried checking the path created by os.path.abspath(os.path.join('..', '..')) and even copied the Flopy directory to that location and running the script from the Anaconda prompt started in that folder...which did make some difference, but the import failed with error: ImportError: cannot import name getfullargspec.
Any ideas why imports work one way but not the other?
Fixed it with help from #Jainal Patel! I just had to tidy up all my environment paths. There was an installed version of Python in C:\Python3, but Spyder was using the one in C:ProgramData\Anaconda.
Now when I open the command prompt, or an Anaconda prompt, or use Spyder, it uses the same Python environment and recognizes all my installed packages.
!pip install flopy
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
you need to install it first either using pip or conda

Spyder can not import plyfile

I have installed plyfile in the Scripts subdirectory of the Anaconda3 (I run Windows 10), using the pip3. When I enter the command
import plyfile
in the Python 3.5 Shell, the command is executed without problems.
But when I move to Spyder and I enter the same command in the console I receive an error message:
import plyfile
Traceback (most recent call last):
File "<ipython-input-3-db7ef797d821>", line 1, in <module>
import plyfile
ImportError: No module named 'plyfile'
I tried to add the path of the file to the environment using the Windows Commander and giving at the C:\ the command:
sys.path.append(C:\Users\Alexandros_7\Downloads\plyfile-0.4)
but I received the error message:
"sys.path.append" is not recognized as an internal or external command, operable program or batch file
I also tried the following commands from the console of Spyder:
import sys
sys.path.append("C:\\Users\\Alexandros\\Downloads\\plyfile")
These commands were executed without a problem. Then I entered, import plyfile and I received the same error message -- i.e. that "No module named "plyfile"".
Could you please help me?
try give Spyder the same environment paths like Anaconda, in your case the path to the installed plyfile eg.:
your_module is located in: "C:\Users\Alexandros\your_module.py"
in Spyder:
lets add the located path to the system environment
import sys
sys.path.append("C:\Users\Alexandros\") #need string
lets import your module
import your_module
reload(your_module)

Import error with module in Python 2.7

I've spent the better part of an afternoon trying to import the xlrd module, it works when i do it in the shell but when i try to run any file I get an import error.
Please could somebody provide a solution? (I'm a beginner, so please be excruciatingly specific)
This code:
#!/usr/bin/python
import os
os.chdir("C:/Users/User/Documents/Python/xlrd")
import xlrd
returns the error:
Traceback (most recent call last):
File "C:\Users\User\Documents\Python\Programs\Radiocarbon27.py", line 4 in <module>
import xlrd
ImportError: No module named xlrd
The path of the setup.py which contains the setup.py file is C:\Users\User\Documents\Python\xlrddocs
thanks!
Click the Start button, click All Programs, click Accessories, and then click Command Prompt.
Type Python then hit enter.
If you get the following, then you have to setup your environment variables.
'python' is not recognized as an internal or external command,
operable program or batch file.
If Python started, then you do not have to setup your environment variables.
Close the command prompt and open another one.
In the new command prompt type: cd C:\Users\User\Documents\Python\xlrddocs
Then type: Python setup.py install
That's it! Now in your .py file type:
import os
import xlrd
The xlrd package is not installed.
For example, you can do
$yum install python27_xlrd-0.9.3

Paramiko and Crypto Import Error: import winrandom (python)

Running on a windows machine python 2.7, whenever I try to run my script using the command line I receive the following error.
import winrandom
ImportError: DLL load failed: The specified module could not be found.
But this error does not happen when I run my script through a python IDE
Make sure your PATH correctly includes your python2.7 and python2.7\Scripts directories.
Snippet on settings environment variables (if needed):
http://msdn.microsoft.com/en-us/library/ms682653%28v=vs.85%29.aspx

Categories

Resources