For at least 99% of my jupyter/ipython notebooks i use the following imports:
import pandas as pd
from pandas.io.json import json_normalize
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from bson import json_util, ObjectId
import json
from datetime import datetime, timedelta
import pytz
pd.set_option('max_columns', 50)
mpl.style.use('ggplot')
%pylab inline
Has anyone discovered any sort of solution that would allow me to do this automatically or create some sort of macro?
Yep, you can do it with customized startup scripts. Mines are in /Users/user_name/.ipython/profile_default/startup. The scripts should be python score files (.py) and the automatic imports should go there.
The doc is here.
If you want to have %pylab inline in your startup script, the script has to be stored with .ipy extension, to specify it is an ipython script not a regular python script. I don't think it will work right if you have the cell magics like %pylab inline in a regular python script.
I like to use the %load magic. Make a file with all the imports in, leave it in the home directory and start the notebook with
%load my_imports.py
This method lets you edit the imports before running them.
Related
vscode doesn't give any Code Action import suggestions for a specific python module I install in the python environment (it's a module I created). I can manually add the import - works. I get import suggestions for all other modules I installed . I can also follow up code into the module (after I have the import, go to definition works). It seems it's only missing as a source of import suggestions.
Is the module missing something?
At the beginning of my IJulia notebook, I have the following preamble that imports several libraries and puts them on all processors:
addprocs(4)
import PyCall
#everywhere using PyCall
#everywhere #pyimport numpy as np
#everywhere #pyimport scipy as sc
.
.
.
The format is from the excepted answer to one of my previous questions. What I want to do now is add the processors and import all my packages in one line. However, I am not sure what would be the most efficient way to do this. I am collaborating with several people on different scientific projects, and I would prefer this importing process to be as simple as possible. Should I make a separate file calling these libraries and then run that file, or should I make my own package that does the above--i.e., define a package that automatically adds the processors, imports the packages, and puts them on all processors?
I am getting the following error while trying to run a sympy file in order to contribute to sympy. It is :
ImportError: No module named sympy
I installed the sympy module through pip for both python2.7 and python 3.
Also, isympy is working.
Strangly, when I try to import sympy in python's interactive console in the main sympy directory, no import errors are shown but in some other directory, it shows import errors.
Please help me to download the sympy module in a way that I will be able to run the code.
Thanks.
Importing module in python console of main directory.
Importing module in some other directory.
A likely cause here is that you are using two different Pythons. If you have Python installed multiple times (like Python 2 and Python 3), each has its own separate packages. You can check what Python you are using by printing sys.executable.
I should point out that for the purposes of contributing to SymPy, you generally want to run against the development version. That is, running Python from the SymPy directory and importing the development version from there, without actually installing it.
Thanks for the reply.
But I solved the problem. I realised that I didn't install sympy in the current conda environment. When I tried it using the command:
conda install sympy
It worked and no error is being shown.
Thanks.
I am searching to do a little programm with 3D animations for one homework for my school.
I work in Spyder space from Anaconda(Python) .
I want to import for that the module vpython installed by pip.
The first line of the function " from visual import * " doesn't work whereas in all examples found on the web, all the programms begins by this line for calling the whole function of this module. Also, i have seen different path and files "vpython" installes on my PC in the path Anaconda3.
So, for me, python don't arrive to find the good path with "import".
Have I to uninstall and install again Python and Anaconda or this is just a problem of grammary from me on my programm and i must help the function import to find the good path, writing some new instructions?
Thanks to have read and i wish you have one idea of what is wrong in this because for the moment I'm blocked.
In Jupyter/iPython/Anaconda, the import should be
from vpython import *
In classic VPython, it's
from visual import *
I've been playing around with using Swift as a scripting language, as described here. When executing script files from the terminal in this way, is there a way to include other Swift files by path (i.e. import /path/to/some/file.swift)? I'm aware of the import statement, but that doesn't seem to accept a file path. In Ruby I would use a require statement, but I don't know if there is a Swift equivalent to this.
import only works with modules. If you need to import a module which is located somewhere besides the normal import search path, you can add another directory to the search paths by passing the -I flag to the compiler:
-I <value> Add directory to the import search path
If you're looking at just a .swift file, you'll need to compile that into a module before you can import it from a separate module or the REPL.