3

I came across this link:

(Python) Use a library locally instead of installing it

And followed the steps to provide path to IBPy package which I downloaded and extracted on my desktop.

My code looks like:

import sys
sys.path.append('C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib\ib')
import IbPy

But the error on third line is: No module named IbPY. I tried different variants on the path for IbPy as: C:\Users\Duck\Desktop\IbPy-0.7.6-9.51

Any suggestions ? My problem is I can't install packages even locally. Only thing I am allowed to do is bring packages through USB.

Edit:

(1) Yes there is init.py file

(2) I am now using

sys.path.append(r'C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib\ib')

The error is still there.

I am using Pycharm as my editor and I downloaded the IBPy from:

https://github.com/blampe/IbPy

Community
  • 1
  • 1
Zanam
  • 4,607
  • 13
  • 67
  • 143
  • Does the `ib` folder have `__init__.py`? You may want to create an empty one in order to use functions from there. – ajmartin Dec 19 '15 at 00:48
  • You have a `\x08` in there so you string is appended as `C:\Users\Duck\Desktop\IbPy-0.7.6-9.5uild\lib\ib` – Padraic Cunningham Dec 19 '15 at 00:50
  • What's in `r'C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib\ib'`? From peeking at github, it looks like you should `sys.path.append(r'C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib')` and `import ib` (not `ibPy`). – tdelaney Dec 19 '15 at 01:24

2 Answers2

3

Use raw strings for Windows paths. The \b is being interpreted as a backspace character.

r'C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib\ib'

should work. Raw strings prevent the interpretation of backslash escapes for all but the string's quote character.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
1

The package is the shallowest directory with an __init__.py and that directory name is the package name. sys.path needs to include the directory before the package directory because python will append the package name to the names in sys.path until it finds a match. Since the directory ib holds the package __init__.py you need to

import sys
sys.path.append(r'C:\Users\Duck\Desktop\IbPy-0.7.6-9.51\build\lib')
import ib
tdelaney
  • 73,364
  • 6
  • 83
  • 116