IPython: redirecting output of a Python script to a file (like bash >)

I have a Python script that I want to run in IPython. I want to redirect (write) the output to a file, similar to: python my_script.py > my_output.txt How do I do this when I run the script in...

How to set the matplotlib figure default size in ipython notebook?

I use "$ipython notebook --pylab inline" to start the ipython notebook. The display matplotlib figure size is too big for me, and I have to adjust it manually. How to set the default size for...

Measure (max) memory usage with IPython—like timeit but memit

I have a simple task: in addition to measuring the time it takes to execute a chunk of code in Python, I need to measure the amount of memory a given chunk of code needs. IPython has a nice...

ipynb import another ipynb file

Interactive Python (ipython) is simply amazing, especially as you are piecing things together on the fly... and does it in such a way that it is easy to go back. However, what seems to be...

How to install a package inside virtualenv?

I created a virtualenv with the following command. mkvirtualenv --distribute --system-site-packages "$1" After starting the virtualenv with workon, I type ipython. It prompts me WARNING:...

How to exclude multiple columns in Spark dataframe in Python

I found PySpark has a method called drop but it seems it can only drop one column at a time. Any ideas about how to drop multiple columns at the same time? df.drop(['col1','col2']) TypeError ...

Folium map not displaying

Running on canopy version 1.5.5.3123 With; Folium Version: 0.1.2, Build: 1 The following code; import folium import pandas as pd LDN_COORDINATES = (51.5074, 0.1278) from IPython.display import...

In which conda environment is Jupyter executing?

I have jupyter/anaconda/python3.5. How can I know which conda environment is my jupyter notebook running on? How can I launch jupyter from a new conda environment?

pyspark : NameError: name 'spark' is not defined

I am copying the pyspark.ml example from the official document website: http://spark.apache.org/docs/latest/api/python/pyspark.ml.html#pyspark.ml.Transformer data = [(Vectors.dense([0.0, 0.0]),),...

tkinter in Spyder

I am trying my first steps in tkinter. I use Spyder as IDE in Python 3.5.1 |Anaconda 4.0.0. I want to run the very simple script below but it always crashes my Spyder. In a normal shell/bash it...

How to disable password request for a Jupyter notebook session?

I have been launching Jupyter Notebook for years using the following command: jupyter-notebook --port=7000 --no-browser --no-mathjax When I try to open the jupyter on the browser it ask me for a...

Conditional cumulative sum in Python/Pandas

Consider my dataframe, df: data data_binary sum_data 2 1 1 5 0 0 1 1 1 4 1 2 3 1 3 10 0 ...

How do I use a new ipython kernel in Atom?

I created a data_science kernel for ipython by using the following commands: python -m ipykernel install --user --name data_science --display-name "Python (Data Science)" This creates a kernel...

How to resolve keras.callbacks import errors for TensorBoard?

Attempt 1 from keras.callbacks import TensorBoard from keras.models import Sequential from keras import layers from keras.optimizers import RMSprop tb_callback =...

Airflow BashOperator OSError: [Errno 2] No such file or directory

I keep getting the same error from a scheduled BashOperator that is currently back-filling (it's over a month "behind"). [2018-06-10 22:06:33,558] {base_task_runner.py:115} INFO - Running:...

Turtle does not run more than once in jupyter notebook

I am trying to run some turtle code in jupyter notebook. When I run the code once, the code runs fine. However, if I run the code again, Python Turtle Graphics freezes and closes (aka python...

Can't run turtle on jupyter notebook (turtle graphic window not responding)

First Question I was doing an example from ThinkPython 2e Chapter 4 Case Study: Interface Design, when I stumbled upon turtle module. I use jupyter notebook as an IDE to do exercise. Here's the...

How to replace all instances of /N with NaN in a csv file using Python

I've read a csv file into Python, and it contains many objects for which the value is \N. I need to replace all of those instances with 'NaN'. I've gotten the file to read in correctly, but I get...

PyTorch BERT TypeError: forward() got an unexpected keyword argument 'labels'

Training a BERT model using PyTorch transformers (following the tutorial here). Following statement in the tutorial loss = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask,...

How to use psycopg2-binary in Python?

I installed the psycopg2-binary package using pip install psycopg2-binary. But when how can I use it in Python? import psycopg2 as pg2 conn = pg2.connect(database = 'dvdrental', user = 'postgres',...

Unable to find a valid cuDNN algorithm to run convolution

I just got this message when trying to run a feed forward torch.nn.Conv2d, getting the following...

Running a ProcessPoolExecutor in IPython

I was running a simple multiprocessing example in my IPython interpreter (IPython 7.9.0, Python 3.8.0) on my MacBook and ran into a strange error. Here's what I typed: [In [1]: from...

'NoneType' object is not iterable for collocation function

I am new to NLTK and trying to return the collocation output. I am getting the output and along with it, I am getting none as well. Below is my code, input and output. import nltk from nltk.corpus...

tensorflow error: "No OpKernel was registered to support Op 'TPUReplicatedInput'" when restoring model

(Novice question; sorry in advance.) I have a pretrained (BigGAN) tensorflow model that another user developed to create images, and I would like to use it to generate new images. (If it helps to...

How to use Wordnet 3.1 with NLTK on Python?

Important Edit As informed by @Pengin in comments. NLTK is supporting WordNet 3.1 from January 2022. Thus this question is deemed irrelevant now. I need to use Wordnet 3.1 for my research work,...

How to clear Colab Tensorflow TPU memory

I am executing model for several folds. After each fold I want to clear the TPU memory so that I don't get OOM error. Full trace of the current error. ResourceExhaustedError ...

Cannot pip install mediapipe on Macos M1

Hello fellows I'm using mac air with M1 chip My env sets like (CV) san  ~/work/python  conda list # packages in environment at /Users/san/miniforge3/envs/CV: # # Name ...

ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly. Importing fiona resulted in:

Trying to read a shapefile (.shp) and received an ImportError after executing the below line of code. I even pip installed GDAL, geopandas, fiona and shapely before executing the below...

How to source or activate a virtual environment within an IPython shell?

I use IPython and the %bookmark magic command but the limitation is that I need to exit the IPython shell to activate a virtual environment and then relaunch IPython. Is there a way, built into...

How to log production database changes made via the Django shell

I would like to automatically generate some sort of log of all the database changes that are made via the Django shell in the production environment. Our code base is version controlled so if we...