Pydev: IPython is NOT available after Adding src folder to PYTHONPATH - eclipse

I'm using Eclipse kepler & pydev 3.4.1 on Ubuntu 12.04.
I installed ipython 0.12.1 via pip, which was located in /usr/lib/python2.7/dist-packages/, so I added this path to PYTHONPATH via eclipse->preference->PyDev->Interpreters->Python Interpreter->System PYTHONPATH.
By this way, I would start IPython in the interactive console(just press CTRL_ALT_ENTER), the output is :
Python 2.7.3 (default, Feb 27 2014, 20:00:17) Type "copyright",
"credits" or "license" for more information.
IPython 0.12.1 -- An enhanced Interactive Python. ? ->
Introduction and overview of IPython's features. %quickref -> Quick
reference. help -> Python's own help system. object? -> Details
about 'object', use 'object??' for extra details.
PyDev -- Python IDE for Eclipse For help on using PyDev's Console see
http://pydev.org/manual_adv_interactive_console.html
It looks fine, but when I try to run a simple code in the interactive console, say:
from common_function import *
if __name__ == '__main__':
print("hello")
It shows me an ImportError:
File "/git/mycode/python_lab/pylab/simple_test.py", line 7, in
from common_function import *
ImportError: No module named common_function
Here, the simple_test.py and common_function.py are placed in the same src folder, and I find some posts on stackoverflow saying that adding the src folder which contatins all the py files to project's PYTHONPATH would solve this problem, so I tried and it did solve the ImportError, but the IPython is disable, the output of interactive console is :
/usr/bin/python2.7 2.7.3 (default, Feb 27 2014, 20:00:17) [GCC 4.6.3]
PyDev console: using default backend (IPython not available).
runfile('/media/data/yanglin/local/work/git/mycode/python_lab/pylab/simple_test.py')
hello
Any one know how to fix this problem?

Related

Python Visual Studio Code cannot find module

I'm importing debugpy into my code and it works, but VSCode complains that it cannot be imported:
The interpreter shows that I am in the same venv as my terminal:
In my terminal (in VSCode) I can list debugpy and import it at the Python prompt.
(python4uvm_examples) raysalemi#RayProMac python4uvm_examples % pip list | grep debugpy
debugpy 1.4.1
(python4uvm_examples) raysalemi#RayProMac python4uvm_examples % python
Python 3.8.5 (default, Sep 4 2020, 02:22:02)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import debugpy
>>>
How do I get VSCode to see that it can be imported?
they have this bug for some time now. what I do - select another interpreter, then re-select the one I need. usually works. (using Pylance as language server).

How can I import local package dependencies into Kedro notebooks?

I've placed package dependencies (wheels) of a Kedro project into a <project-root>/deps/*.whl directory. I'm using a venv installed into <project-root>/.venv and manage it using Poetry.
Packages are referenced in pyproject.toml like this (here e.g. local-package):
[tool.poetry.dependencies]
local-package = {path = "deps/local_package-X.Y.Z-py2.py3-none-any.whl"}
The package can be imported in a REPL session:
$ .venv/bin/python
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import local_package
>>>
In VSCode I've activated my venv and am running `kedro jupyter lab` to start jupyter lab. If I try to import the package it cannot be found (running `import local_package` in a notebook cell leads to `ModuleNotFoundError: No module named "local_package"`). If I run `!poetry show | grep local-package` in a notebook cell I get `local-package X.Y.Z deps/local_package-X.Y.Z-py2.py3-none-any.whl`. The Python interpreter shown in Jupyter Lab is the project one. What do I have to do to get this working?

Visual Studio Code and pylint not finding module issues

First, I may have more of an issue with correct environment selection. I did a fresh install of Linux Mint 19 and apt dist-upgrade... etc... and then used apt-get and pip to install pymysql, pil.intertk and pylint for both python and python3 from the cli...
All is good from cli:
~$ python3 --version
Python 3.6.5
~$ pylint3 --version
No config file found, using default configuration
pylint3 1.8.3,
astroid 1.6.0
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0]
python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> import PIL
>>>
After installing VSC.... the only two selection of python environments are 2.7.12 and 3.5.2 ?
I then modified VSC settings with: "python.pythonPath": "/usr/bin/python3"
Which still shows as Python 3.5.2 64-bit within VSC
But here comes my issue that I have tried many suggestions I have found from searching with no luck...
pylint is not finding any module I install. I assume its due to the mix match of version ? But not sure how to resolve that?
When I try to specify the pylint path : "python.linting.pylintPath": "/usr/bin/pylint3"
I get an invalid path error in VSC.. but its a valid path
~$ which pylint3
/usr/bin/pylint3
Any help would be greatly appreciated....
So after some frustrating trail and error I have fixed the issue by uninstalling the Flatpak version of Visual Studio Code listed in the Linux Mint's Software Center... and installing the deb package from the official site.
After installing the deb package... the proper version of python are showing and pylint is working correctly.

itorch creates a python console, not a torch console

When I call itorch I don't get a torch console but an ipython console:
~$ itorch
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
Type "copyright", "credits" or "license" for more information.
IPython 0.12.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
IPython profile: torch
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-4469.json --profile torch
In [1]: require 'nn'
File "<ipython-input-1-d76f3f5020d1>", line 1
require 'nn'
^
SyntaxError: invalid syntax
In [2]: import os
In [3]:
What do I do wrong?
iTorch supports iPython v2.3 or above. Please see the required dependencies.
You seem to have iPython v 0.1.2, maybe that's a reason you see this behavior.

IPython not available in PyDev console

I would like to use the IPython interpreter in Eclipse/PyDev.
PyDev however does not recognize my IPython installation.
The results I get is the following:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
PyDev console: using default backend (IPython not available).
D:\QuantumGIS\apps\Python25\python.exe 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
>>> import IPython
>>>
The "import IPython" command does work.
I'm using
Windows XP 32 bit
Eclipse 3.7.2
PyDev 2.4.0
IPython 0.10.2
Python 2.5 (version that is supplied with QGIS 1.7.3)
How should I set up PyDev so I can use IPython as the interactive interpreter?
Not sure if it's the same issue but from Fabio's blog he said to try in the python console (import IPython worked ok):
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
which gave me nothing useful and:
from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
Which complained that twisted wasn't installed. I installed twisted 12.0 for Python 2.5 and it's dependency Zope (3.8 for Python 2.5), restarted the IDE and the console now shows ipython. There was something about ipython actually using XMLRPC to communicate with the IDE so I guess twisted is needed for that.
Hope that helps.
Stu.
Windows 7
Aptana studio 3.1.2 (version of eclipse)
PyDev 2.5.0 IPython 0.10
Python 2.5 (needed for some old code I'm working on and haven't
upgraded yet)