I am trying to run a python code using VS code, I noticed that the result is different from the local terminal.
here is the code:
import tensorflow as tf
from tensorflow import keras
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
a=tf.constant(10)
print(f"a = {a}")
its successfully running using my local terminal and I am having the error below while using my vs code terminal.
File "00-test.py", line 11
print(f"a = {a}")
^```
you can check if the two pythons in vscode terminal and local terminal have the same version,or with the same enviro
Related
In a python script file I have:
import sklearn
iris=sklearn.datasets.load_iris()
This works:
$ ipython <this script file>
But now I do in the script file:
import sklearn as sk
iris=sk.datasets.load_iris()
If I do the same as above, I see:
AttributeError: module 'sklearn' has no attribute 'datasets'
This is what I do not understand. Also in interactive ipython the last import and assignment work!
Also:
import scipy as sp
p1=sp.special.expit(Phi#w)
works in a script file (given to ipython)! Looks like the same as above with sklearn where it did not work.
When I run the following code in PyCharm on a Mac:
import numpy as np
import pandas as pd
from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))
import time
import copy
import numpy as np
import pandas as pd
import chainer
import chainer.functions as F
import chainer.links as L
from plotly import tools
from plotly.graph_objs import *
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
init_notebook_mode()
data = pd.read_csv('../input/Data/Stocks/goog.us.txt')
data['Date'] = pd.to_datetime(data['Date'])
data = data.set_index('Date')
print(data.index.min(), data.index.max())
data.head()
There were some errors:
UserWarning: Accelerate has been detected as a NumPy backend library.
vecLib, which is a part of Accelerate, is known not to work correctly with Chainer.
We recommend using other BLAS libraries such as OpenBLAS.
For details of the issue, please see
https://docs.chainer.org/en/stable/tips.html#mnist-example-does-not-converge-in-cpu-mode-on-mac-os-x.
Please be aware that Mac OS X is not an officially supported OS.
''') # NOQA
Traceback (most recent call last):
File "/Users/yindeyong/Desktop/PythonProjects/pythonstock/DQNStcok.py", line 33, in <module>
init_notebook_mode()
File "/Users/yindeyong/Desktop/PythonProjects/envs/stockenv/lib/python3.6/site-packages/plotly/offline/offline.py", line 250, in init_notebook_mode
raise ImportError('`iplot` can only run inside an IPython Notebook.')
ImportError: `iplot` can only run inside an IPython Notebook.
Process finished with exit code 1
I'm new in Chainer and DQN. Could anyone help me edit this code to make it work? Thank you so much!
It seems like you're trying to run plotly interactive functions (i prefix) in a normal Python code (i.e. not IPython Notebook). iplot provides an interactive graph with which you can play inside the notebook.
I'd start with removing iplot import and replacing it with normal plot. Also, remove iplot_mpl and init_notebook_mode from your imports.
You can install 'ipython' in the virtual environment and then try running it directly from the terminal.
Activate the virtual environment
pip3 install ipython
python3 prog.py
Worked in my case.
I have the following python code:
import tensorflow as tf
import numpy as np
import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
num_house = 160
np.random.seed(42)
house_size = np.random.randint(low=1000, high=3500, size=num_house)
I am trying to debug this python code in visual studio code. I have selected the right configuration (Python: Current File (Integrated Terminal)). I have set my breakpoint on the last line. When i run from the debug console, my code fails giving me a ModuleNotFoundError. But I am able to execute this program in the terminal. How do I debug this code in vs code?
I am following Google's Machine Learning Crash Course, so that I can move on to TensorFlow. However, when I try to execute the code in First Steps With TensorFlow, I get no output from the following line:
california_housing_dataframe.describe()
Here is my full code in case it helps:
import math
from IPython import display
from matplotlib import cm
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sklearn import metrics
import tensorflow as tf
from tensorflow.python.data import Dataset
tf.logging.set_verbosity(tf.logging.ERROR)
pd.options.display.max_rows = 10
pd.options.display.float_format = '{:.1f}'.format
california_housing_dataframe = pd.read_csv("https://storage.googleapis.com/mledu-datasets/california_housing_train.csv", sep=",")
california_housing_dataframe = california_housing_dataframe.reindex(np.random.permutation(california_housing_dataframe.index))
california_housing_dataframe["median_house_value"] /= 1000.0
california_housing_dataframe.describe()
So far, I have tried the following:
Execute the .py file with the python command.
Execute the .py file with the ipython command. I also tried to use arguments -i -c (i.e. ipython -i -c "%run filename.py").
Open ipython.exe and use the run command to execute my script.
Open ipython.exe and copy the code line by line.
Out of the above, only copying every line individually into IPython gave proper output. Is there a way to execute my script without having to copy every line in IPython?
Within a program only the function creating the summary in describe() is executed; in a console environment silently the result is automatically printed as well, as this is what you typically want to see there.
In your program you would have to call
print(california_housing_dataframe.describe())
explicitly.
The interactive python console, jupyter console etc are geared up to allow you to type a variable name, or it's attribute to display it. This is not the case when running a script non-interactively. Instead you must use the print() function.
print(varaible_name.attribute)
I have plotted a graph from a CSV file using SPYDER from PYTHON
Here is my code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('GM_NB_Replica_Test.csv', skiprows=8)
data = df.ix[:,19:116].T
data.columns=df['SN']
data.plot()
plt.show()`
Here is my Output inside the python console:
How do i get this to run externally (Not inside python console, and not in new python console)
I have already tried changing the run settings (See photo below)
However it just gives me a black Python CMD and then no graph.
any thoughts?
current error when running in CMD
From your command prompt (CMD):
cd C://location_of_your_script
python script.py