itorch creates a python console, not a torch console - ipython

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.

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 do I get the IPython version I'm currently using?

How do I get the IPython version I'm currently using?
I'm aware of sys.version, but that's the Python version I'm currently using.
Edit: And I'm aware of ipython --version, but I want to check inside the current IPython session. !ipython --version doesn't work for me cause I might have multiple IPython versions installed.
You can import IPython, then use IPython.version_info to get it as a tuple, or IPython.__version__ to get it as a string. For example:
In [1]: import IPython
In [2]: IPython.version_info
Out[2]: (4, 1, 2, '')
In [3]: IPython.__version__
Out[3]: '4.1.2'
IPython.version_info seems to be the same layout as sys.version_info: major, minor, micro, releaselevel.
Run the following command in the terminal:
ipython --version

Conda always opens root environment

If I 'source activate' a non-root environment (in my case "data"), then launch Jupyter notebook, the env seems to switch to root. I can tell because if I try to open a new python notebook, the dropdown under New says Python [Root]. I am also unable to import packages in my env, but not in root.
(data) Edwards-MacBook-Pro:~ mango$ conda list
# packages in environment at /Users/mango/anaconda/envs/data:
#
boto 2.42.0 py35_0
bz2file 0.98 py35_0
cycler 0.10.0 py35_0
freetype 2.5.5 1
gensim 0.12.4 np111py35_0
libpng 1.6.22 0
matplotlib 1.5.1 np111py35_0
mkl 11.3.3 0
numpy 1.11.1 py35_0
openssl 1.0.2i 0
pandas 0.18.1 np111py35_0
pip 8.1.2 py35_0
pyparsing 2.1.4 py35_0
pyqt 4.11.4 py35_4
python 3.5.2 0
python-dateutil 2.5.3 py35_0
pytz 2016.6.1 py35_0
qt 4.8.7 4
readline 6.2 2
requests 2.11.1 py35_0
scikit-learn 0.17.1 np111py35_2
scipy 0.18.1 np111py35_0
seaborn 0.7.1 py35_0
setuptools 27.2.0 py35_0
sip 4.18 py35_0
six 1.10.0 py35_0
smart_open 1.3.4 py35_0
sqlite 3.13.0 0
tk 8.5.18 0
wheel 0.29.0 py35_0
xz 5.2.2 0
zlib 1.2.8 3
(data) Edwards-MacBook-Pro:~ mango$ ipython
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12)
Type "copyright", "credits" or "license" for more information.
IPython 4.2.0 -- 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.
In [1]: import seaborn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-085c0287ecb5> in <module>()
----> 1 import seaborn
ImportError: No module named 'seaborn'
In [2]:
The same behavior occurs with gensim, so it is not just seaborn.
I managed to solve the issue. Conda installs the [root] environment with ipython and jupyter. If you create an env, those are not available by default. So when creating and env, either be sure to list those packages explicitly, or clone root. Cloning root may make a bulkier env and it may be less desirable for production, but better for a sandbox context.
I discovered this issue by trying the same test above with python and finding that my packages indicated that I was in the data env. I then decided to try the Anaconda Navigator program with conda install anaconda-navigator. While I like a cli, this GUI based program seems like a better way to manage packages.

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

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?

Import Requests Error

I am starting to use requests lib and beautifulsoup lib. My goal is to extract data from Twitter, and do some hot topic analysis.
After I installed Python 2.7.5 on windows 7 system, I can import urllib2, but I can not import requests or BeautifulSoup.
Here is the error message below. Can someone help me here?
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
>>> import requests
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module>
import requests ImportError: No module named requests
I have googled a lot but find little hint on my situation. If you think that more info is needed to solve the problem, please leave a note here, I will be more than glad to provide the info that's needed.
Any help will be appreciated. Thanks!
I had a similar problem.
Mac OSX, IDLE Python 3.6:
Installed the module requests using the following commands:
import pip
pip.main(["install","--user","requests"])
The result was:
Successfully installed requests-2.12.4
But then I could not import the module requests using the command "import requests". But also not the command "import requests-2.12.4" was running in the IDLE. Running on a shell starting with "python3" I could run the standard import command "import requests" successfully.
So I did quit the IDLE and started it new. And then it did run as expected.
Maybe this helps you too!