I am trying to load things like from __future__ import division on the IPython startup on windows 7 64 bit machine, python 2.7 64 bit.
I searched the web and the recommended way I found is to put a .py file with instructions in: C:\Users\Me\.ipython\profile_default\startup. I've put a simple .py file containing
from __future__ import division
from __future__ import unicode_literals
in that folder. But it actually does nothing. What is more confusing is that the file seems to execute, because if I put some random error line in there, i see an error on Ipython start. Still division is not imported and have to re-import it typing from __future__ import division in the shell.
I tried it both on Anaconda and Winpython(settings for IPython on this distribution are in other folder) with the same result. After I re-import everything works fine. Totally stuck here, please help!
Check to see if C:\Users\Me\.ipython\profile_default\ipython_config.py exists. If it doesn't, run
ipython profile create
from the command line to generate it. Next, open it in your favorite text editor and search for c.InteractiveShellApp.exec_lines. Uncomment that line (it's line 27 in my file) and edit it to be the following:
c.InteractiveShellApp.exec_lines = ["from __future__ import division", "from __future__ import unicode_literals"]
Save the file, restart IPython, and you should be all set.
Related
So I am trying to run some scripts just by opening the python file directly (not running through pycharm). However, when I import certain libraries (such as numpy or matplotlib) the terminal will close automatically, even if the program is waiting for user input. All of these scripts run without error in pycharm.
Here is an example of some imports that don't close the window automatically:
import tkinter as tk
import math as m
input('press enter to return')
Here is an example of some imports that do close the window automatically:
import numpy as np
import matplotlib as m
input('press enter to return')
What is going on here? I am relatively new to coding and so I think I might be missing something fundamental.
This might be because anaconda has not been installed to your system path, it's important to have python interpreter and IDE being set to PATH especially when you are working with libraries that are not pre-installed
Hope it cleared your doubts, if any errors, do let me know
Cheers
import numpy
is not working. This started because I couldn't get PyQt5 to work on my home computer. In the Spyder IDE, I can import modules and get everything working fine, but in VS Code, I can't import basic modules. I'm on Windows 10 with Python 3.7. I've Googled a lot and have tried these:
Uninstall Anaconda and VS Code, and reinstall both
In VS Code, press Ctrl+Shift+P, Select Interpreter, and select Python 3.7.1 64-bit ('base':conda), ~\Anaconda3\python.exe
I saw on another similar question that python3.dll may be missing from one of my Anaconda directories, but it is indeed there.
Add environment variable to PATH by going to System Properties > Advanced tab > Environment Variables... > under System Path, Edit, New > C:\Users\myname\Anaconda3\Scripts
Once I did #4 above, the new error message in VS Code when importing numpy is DLL load failed: The specified module could not be found. And in the terminal, I see: The term 'conda' is not recognized as the name of the cmdlet, ...
One thing I notice is in a Python prompt (not Anaconda) I type:
import sys
print(sys.version)
The output is 3.7.2, while in VS Code, the Select Interpreter (see above #2) says Python 3.7.1. Not sure if this is important.
Any help? Everything works on my work computer fine, but it's just my home computer that is being difficult.
What ended up working for me is downgrading my Python installation from 3.7.1 to 3.6.4 with:
conda install python=3.6.4
Hope this helps someone out there.
On another question for the same problem, there was a suggestion that worked for me.
Put this on the variable path.
C:\Users\<Your user name>\Anaconda3\Library\bin
credit to user1024.
During interactive IPython notebook sessions, that usually only require normal imports, sometimes there is a need to import an occasional .pyo file.
Is there any IPython magic or a python API to do that?
Python imports .pyo files only if run with with -O option:
python -O
Starting the whole IPyhon Notebook with this option does seem to work. At least I did not get to work.
As this issue points out, a workaround would be to rename the .pyo file into a .pyc file. Than Python will import it:
Actually it's a lot easier than that, although it is very much a hack: just rename the .pyo files to .pyc, and python without -O will happily import them. Since the optimization happens when the bytecode is written, this does what you want.
R. David Murray (r.david.murray)
I would like to use arcpy into Anaconda's Spyder. I have a full ArcGIS license, so this is not an issue. I am able to semi-import the module by way of copying the the arcpy folder out of C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy and into C:\Anaconda\Lib\site-packages, but the import is never completed because I get an error of "ImportError: No module named arcgisscripting". Is there any way for arcpy to work in Spyder?
This is what you need to do:
Open the Python window in ArcGIS, as described here
In there run these two commands:
import sys
sys.executable
Copy the output of the last command
Open Spyder and go to
Tools > Preferences > Python interpreter
Select the option
Use the following Python interpreter
and paste there the result of step 3.
Finally go to Consoles > Open an IPython console. This will open a new console that will be running the same Python version that comes with ArcGIS but inside Spyder. So you could run there whatever command you can run in ArcGIS Python Window.
Note: It is possible that this doesn't work if the Python that comes with ArcGIS doesn't have the ipykernel package.
To address this, browse to the python27\Lib\site-packages folder, mine was located under "C:\Python27\ArcGIS10.1\Lib\site-packages", and find the file Desktop10.1.pth.
On my system, the problem was resolved by simply copying the Desktop10.1.pth file into "C:\AppData\Local\Continuum\Anaconda\Lib\site-packages".
If you are running Anaconda 64 bit, you will get a different error when you try to import arcpy because ArcGIS runs 32 bit. Therefore, you have to make sure that you have the Anaconda 32 bit installed rather than 64 bit so things match up with ArcGIS. Once the file is copied and you have Anaconda 32 bit, import arcpy should work.
The only thing worked for me is: I just copied the arcpy folder from 'C:\Program Flies(x86)\ArcGIS\Desktop10.3' and pasted that into my '~Anaconda3\Lib\site-packages'. Now I can import arcpy into spyder of Anaconda3.
i'm looking at the Ipthon in depth videos. One of the first execises is import files from the dashboard. It's a very simple process, preesing the "click here" to import the file, select the ipython notebook file, and that's it. That's why i'm very frustrated. Every time i do this, the name of the file is on the list for a few seconds (with the upload button), and then disappears, without any error message on the dashboard nor in the terminal. There's is some kind of verbose output so i can see what's happen? I'm using Ipython 0.13.2 on fedora 18
Thanks!
Until you get a complete answer this might work. When I was having issues with this (a complete cleanout and reinstall of IPython sorted it for me), I could still import files by using the drag and drop interface.
I am on Win7 64 so different OS