<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amin Asbai on Medium]]></title>
        <description><![CDATA[Stories by Amin Asbai on Medium]]></description>
        <link>https://medium.com/@aminasbai?source=rss-67316fab25e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bvF66Rxz0YB8uyKB_cpcjA.jpeg</url>
            <title>Stories by Amin Asbai on Medium</title>
            <link>https://medium.com/@aminasbai?source=rss-67316fab25e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:20:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aminasbai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hypertuning a LSTM with Keras Tuner to forecast solar irradiance]]></title>
            <link>https://medium.com/analytics-vidhya/hypertuning-a-lstm-with-keras-tuner-to-forecast-solar-irradiance-7da7577e96eb?source=rss-67316fab25e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7da7577e96eb</guid>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[renewable-energy]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Amin Asbai]]></dc:creator>
            <pubDate>Tue, 20 Jul 2021 15:19:10 GMT</pubDate>
            <atom:updated>2021-07-26T06:22:11.758Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzFivpRKKzTkXjK8eum_WA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@logvisuals?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nuno Marques</a> on <a href="https://unsplash.com/s/photos/photovoltaic?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Project Overview</h3><p>Most of you already know that one of the main issues with photovoltaic energy, and renewable energy in general, is the associated uncertainty with the production in those technologies. This issue makes it hard to integrate them into the grid. If you have any background in electrical engineering you would know that to avoid issues on the grid, we have to match the production and the consumption of energy at every moment in time. If it does not happen, the grid will become unstable.</p><p>When we use traditional power plants, we can dispatch energy as we want. Then the grid operators just have to forecast the power consumption and adjust the power plants accordingly. But, when we introduce renewable energy we cannot dispatch them as we want. Hence, to schedule and coordinate all the different energy sources to supply energy in a reliable manner we need to estimate the renewable energy production.</p><h3>Forecasting Solar Irradiance</h3><p>In my project I used a dataset provided by <a href="https://re.jrc.ec.europa.eu/pvg_tools/es/#TMY">PVGIS</a> that contains meteorological data from a whole year that has been taken on an hourly basis.</p><p>I will use the data from the last 10 days (240 steps) to forecast the solar irradiance for the next day (24 steps).</p><h3>LSTM Overview</h3><p>In recent years, LSTM networks had become a very popular tool for time series forecasting. There are people that argue that aren’t that good, and that tend to overfit. As everything in life I think there is no silver bullet, so you will always have to try different models to choose the right one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YECeOxlko9KoOJNw8RNm3A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alina Grubnyak</a> on <a href="https://unsplash.com/s/photos/neural-network?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>What is LSTM?</h3><p>Long Short-Term Memory is a kind of recurrent neural network (RNN) architecture. The RNN are mainly used in processing sequential data (text, natural language or image captioning) and in time series forecasting. Their main difference with feedforward or convolutional networks is the fact that they have some sort of ‘memory’. RNNs feed the output back as an input, making the output dependent on prior events.</p><h3>Why LSTM?</h3><p>The idea behind RNN was to build a NN that was able to learn to use past information. When the useful information is close in time, RNN can do the job. But If we need to go further back in time RNN fails, and here is where LSTM comes into play. LSTMs are capable of keeping the important information, doesn’t mind of back in time it is, and forget the useless one.</p><p>On the other hand, if we compare it to traditional statistical techniques. LSTM allows to capture complex patterns that traditional techniques would have a hard time to. For example, solar irradiance has multiple seasonalitys (a daily and a yearly one). Capturing that multiple seasonality with, let’s say, ARIMA can be very problematic.</p><p>If you want to learn more about LSTM, <a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/">see that article</a>.</p><h3>What is hypertuning and why it is important?</h3><p>In every machine learning algorithm we have the parameters and the hyperparameters. Parameters are learnt by the algorithm itself by training. On the other hand, hyperparameters are set manually by the user.</p><p>If you are familiar with Neural Networks you will realize there is no clear guidelines or any formal procedure to design and choose the neural network hyperparameters. So, usually trial and error techniques and intuition are used.</p><p>To make that process a bit more efficient Keras has developed a hypertuner, which basically allows you to easily configure a space search where you will deploy a search algorithm to find the best hyperparameter combination.</p><h3>Disclaimer</h3><p>In this post, I will focus just on building the neural network. But, don’t forget to analyze your data before you start building a model. It’s always good to know the data you are working with.</p><h3>Let’s code</h3><p>First of all, we have to import all the modules and packages we will use. It may change according to your project needs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39d7a7ef7f6571636390a919d7b0c28b/href">https://medium.com/media/39d7a7ef7f6571636390a919d7b0c28b/href</a></iframe><h3>Data loading</h3><p>Then, we will load the dataset and clean the data. We won’t talk about data cleansing because it misses the point of the tutorial.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01460b59ea6a579cf88611fa14a89a09/href">https://medium.com/media/01460b59ea6a579cf88611fa14a89a09/href</a></iframe><h3>Data splitting</h3><p>Once we have the data, we will split it into a training set and a validation set. As stated before, we want to do 24 hours ahead forecast. So, we will split the data in a way that both sets will be made up of whole days.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cae1817f68099f23441a9731f0f37e2a/href">https://medium.com/media/cae1817f68099f23441a9731f0f37e2a/href</a></iframe><h3>Transform it into supervised learning</h3><p>Then, we have to transform the data into a supervised learning form. That concept is a bit tricky.</p><p>In a supervised learning problem we have an input (X) and an output (Y) and the task of our machine learning algorithm is to find a function that maps the input to the output.</p><p>When we are working with time series, we have a discrete collection of data. So, we have to reframe that data to a collection of input-output pairs. To do that we will use the previous time steps as input variables and the next step as the output variable.</p><p>Let’s use an example to make it clear, we have the following time series:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bf99ccb36f65087260093f3351cd8bf/href">https://medium.com/media/9bf99ccb36f65087260093f3351cd8bf/href</a></iframe><p>We can reframe it into a supervised learning problem by doing the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e642cbe2454457a415b16be264090607/href">https://medium.com/media/e642cbe2454457a415b16be264090607/href</a></iframe><p>That was a simple case, It gets more complicated when we work with multivariate and multi-step forecasting, as was the case in my project.</p><p>If you are not familiar with the concept I highly recommend you to read this <a href="https://machinelearningmastery.com/time-series-forecasting-supervised-learning/#:~:text=Time%20series%20data%20can%20be%20phrased%20as%20supervised,variable.%20Let%E2%80%99s%20make%20this%20concrete%20with%20an%20example.">article</a> before going further.</p><p>To reframe the dataset I used the following function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a43e1df7b7b4cb75217328934da43e43/href">https://medium.com/media/a43e1df7b7b4cb75217328934da43e43/href</a></iframe><h3>Scale the data</h3><p>Neural networks work better and converge faster with scaled data. There are plenty of articles out there explaining the math behind it. For my application I used a MinMax scaler provided by <em>sklearn, </em>but you can use more sophisticated scalers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3223ca390f713ea1856e690270bf600e/href">https://medium.com/media/3223ca390f713ea1856e690270bf600e/href</a></iframe><p>In the function <em>scale_data</em> we get the training set and the validation set as arguments. Then, we create an scaler for the features and other for the target. We scale the data and we return as output the scaled datasets and the scalers we used.</p><p>Please, don’t scale the training and the testing sets together. It will leak test information back to the train test. The right way to do this is to use only the training set to build the scaler and use the same scaler for scale the test data.</p><p>Be aware, of saving your scaler because on the algorithm deployment phase you will need it to scale the streaming data.</p><h3>Put it all together!!!</h3><p>Now, that we have built all the functions we need. It’s time to put it all together to start training our neural network.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d5c5bf3b62eb4db5410a6982ad4e99/href">https://medium.com/media/d0d5c5bf3b62eb4db5410a6982ad4e99/href</a></iframe><h3>Keras Tuner</h3><p>Until now, we have done nothing special. We have just prepared our data to be trained by a neural network. But, now we are going to apply the Keras Tuner magic!!!</p><p>First, we have to create a function where we will define our model <a href="https://en.wikipedia.org/wiki/State_space_search">space search</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/131810ba4535438dfd6bf78318528d0f/href">https://medium.com/media/131810ba4535438dfd6bf78318528d0f/href</a></iframe><p>Here, I will try to break the code down to make it as understandable as possible.</p><p>The first thing we have to do is instantiate <em>Sequential(), </em>it will be our stack of layers.</p><p>I used a <em>n_layers x LSTM+ Dropout + Dense</em> architecture, but you could use any other. As you may have noticed, selecting the architecture is tricky an requires hyperparameter tuning.</p><h3>Whats is ‘hp’?</h3><p><em>Hp</em> is an object that we pass to the model-building function, that allows us to define the space search of the hyperparameters.</p><h3>First LSTM layer</h3><p>Setting the first LSTM layer is a bit tricky. When we reframed our time series to a supervised learning problem, we have created a 3D array. The first dimension is the number of pairs input-output and it is inferred by the layer itself. The second dimension is the number of backward steps, for example, I used the data of the 10 previous days (240 steps) and the third dimension is the number of labels used, in my case 8 (temperature, irradiance, pressure, etc.). The second and third dimensions have to be set explicitly on the first LSTM layer (line 3).</p><p>Another important thing is to set <em>return_sequences</em> to <strong>True</strong>, <strong>False</strong> is the default value. When we set <em>return_sequences </em>to <strong>True,</strong> it makes the output usable to another LSTM. If the next layer is not an LSTM, just leave <em>return_sequences</em> by his default value.</p><p>If you want to learn more about it, check that <a href="https://machinelearningmastery.com/stacked-long-short-term-memory-networks/">post</a>.</p><h3>Chossing the number of neurons</h3><p>There is no way of knowing the right number of neurons a layer should have. That’s why we use the <em>hp</em> object to define a range of values the hyperparameter can take.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ffdc0dd4c3b4e12b5596718d437bf70/href">https://medium.com/media/5ffdc0dd4c3b4e12b5596718d437bf70/href</a></iframe><p>In the code above we are telling the Tuner to use values between 32 and 512 with a step of 32.</p><h3>Choosing the number of layers</h3><p>As with the number of neurons there is no way of knowing the optimal number of layers, that’s why we insert a <em>hp.int()</em> in a for loop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8f644a600ff940a30588dd5a28dc440/href">https://medium.com/media/e8f644a600ff940a30588dd5a28dc440/href</a></iframe><p>Here every trial range() will take a new value. For example, the first iteration ‘n_layer’ may take the value 1, which means the loop will have range(1), so we will add 1 LSTM layer, or could take a value of 4 and add 4 layers.</p><h3>Dropout layer</h3><p>To avoid overfitting the neural network, we add a dropout layer. The dropout layer hides neurons randomly, and the number of neurons hidden is set by the dropout rate. If the dropout rate is 0.5, the dropout layer will hide half of the neurons every iteration.</p><p>To find the right dropout rate, we will use <em>hp.float()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a87ecb0bb008e3500be2d18ba208b80d/href">https://medium.com/media/a87ecb0bb008e3500be2d18ba208b80d/href</a></iframe><p>Intuitively, you may notice it works similar to <em>hp.int()</em>, we set a range of values and we set a step, then the Tuner will chose values from that range according to the chosen search algorithm.</p><h3><strong>Dense Layer and activation function</strong></h3><p>In most of LSTM deep learning architecture there is a final dense layer. In my case, I had to choose an activation function that will ensure positive values (it doesn’t make sense to have negative irradiance). To ensure positive values I chose to use a relu or a sigmoid activation function. As usual, there is no way of knowing which one will perform better. But luckily for us, Keras Tuner provides us with <em>hp.choice()</em>, it allows us to set a list of possible choices from where values can be taken.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43890c65ccfd84fb5890da9c14f02c0d/href">https://medium.com/media/43890c65ccfd84fb5890da9c14f02c0d/href</a></iframe><p>In the code above, I’m telling the dense layer the number of outputs I want (<em>Y_train.shape[1]</em>) and I’m setting activation function to be a relu or a sigmoid. Remember <em>Y_train.shape[1]</em> is 24, i.e. a whole day.</p><h3>Compile the model</h3><p>Once, we have built our model we have to compile it. We have to set 3 parameters:</p><ul><li><em>Loss:</em> It defines the metric we will use to measure the error of the model during the training phase</li><li><em>Optimizer:</em> It defines the optimization technique we will use to change the inputs weight. It’s a tricky concept, look at this <a href="https://towardsdatascience.com/overview-of-various-optimizers-in-neural-networks-17c1be2df6d5#:~:text=Optimizers%20are%20algorithms%20or%20methods%20used%20to%20change,to%20solve%20optimization%20problems%20by%20minimizing%20the%20function.">article</a> if you want to know more.</li><li><em>Metric:</em> It is the metric we will use to evaluate our model is similar to <em>loss</em>, but is not used during the training.</li></ul><h3>Create a Tuner object</h3><p>Now, that we have defined our model-building function, we can create a tuner object. When we create a tuner object, we will set the search algorithm we will deploy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f7ea58763678fa512dcc7252557277/href">https://medium.com/media/67f7ea58763678fa512dcc7252557277/href</a></iframe><p>I decided to use a Random Search because of simplicity, but you can choose other (the code may change a bit) but the <a href="https://keras.io/api/keras_tuner/tuners/">documentation</a> is pretty clear. You shouldn’t have problems.</p><p>Then, inside the class we have to set some parameters.</p><p>We have to pass a hypermodel (the model-building function we just created). We have to set the ‘objective’, that’s the metric the searching algorithm will use to evaluate every model trial. As we are dealing with a forecasting problem I’m using MSE as a metric.</p><p>Now, come the two parameters I struggled more to understand at the beginning, but are actually pretty simple.</p><ul><li><em>max_trials:</em> The number of hyperparameters combinations the search algorithm will try. As you may notice, trying every possible combination is unrealistic, so you set how many combination you want the search algorithm to try.</li><li><em>execution_per_trial:</em> As you may be aware of, the neural networks have a remarkable stochastic component, i.e. you can train the same neural network with the same data and get slightly different models. So, if you are looking for the best accuracy possible you may want to retrain the same neural network architecture several times until you find the best one.</li></ul><p>Once, we have created the tuner object, we can use the method search to find the best model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a2a94e79d1b34f323174684d06a9d23/href">https://medium.com/media/7a2a94e79d1b34f323174684d06a9d23/href</a></iframe><p>If you are familiar with neural network you should know what epochs and batch_size is, if not look at this article.</p><h3>Getting the best model</h3><p>After the search has been done (it may take a long time). We are ready to get the best model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/156c1767a6d8232ca932b5b97ae4b798/href">https://medium.com/media/156c1767a6d8232ca932b5b97ae4b798/href</a></iframe><p>Now that we will have our model, I will show you how to use the <em>predict </em>method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eca167696358ff49a72780ca82b9de0c/href">https://medium.com/media/eca167696358ff49a72780ca82b9de0c/href</a></iframe><p><em>X_test[0]</em> is a 2D array, that has 240 values (10 days data) and 8 features (the meteorological features). As you remember, LSTM just takes 3D arrays, therefore we have to reshape <em>X_test[0]</em> to get a 3D array.</p><h3>Save the model and the scalers</h3><p>If you have built and developed a neural network you may want to keep the model to use it afterward or for deploying it.</p><p>I will recommend to save it as .h5 file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/760b44936913e830fe7bc6b98fc61556/href">https://medium.com/media/760b44936913e830fe7bc6b98fc61556/href</a></iframe><p>As I mentioned before, you should save the scaler you used in the training phase to use it after with streaming data. I will recommend saving it as a pickle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09248e6586034e11a8591085eac417fd/href">https://medium.com/media/09248e6586034e11a8591085eac417fd/href</a></iframe><h3>Conclusion</h3><p>My main objective with this post was to give an idea of how to use Keras Tuner and how to use LSTM layers in a deep learning context.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7da7577e96eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/hypertuning-a-lstm-with-keras-tuner-to-forecast-solar-irradiance-7da7577e96eb">Hypertuning a LSTM with Keras Tuner to forecast solar irradiance</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Troubleshooting virtual environment setup with Windows 10 and VSCode]]></title>
            <link>https://medium.com/analytics-vidhya/troubleshooting-virtual-environment-setup-with-windows-10-and-vscode-fdd99fdf4d66?source=rss-67316fab25e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdd99fdf4d66</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Amin Asbai]]></dc:creator>
            <pubDate>Sun, 27 Jun 2021 00:03:26 GMT</pubDate>
            <atom:updated>2021-07-13T15:24:30.996Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, my main computer (Linux) broke down. So, in the meantime, I used my other computer (Windows 10) where I had VSCode installed. And to be honest, I had a difficult time building an application over a virtual environment using VSCode in Windows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qsahpt2kqQ6e8iM5lqfZNg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ralexnder">Alex Chumak </a>on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><h3><strong>What is a virtual environment?</strong></h3><p>Probably most of you already know what a virtual environment is, but for those of you who don’t. Here comes a quick and hopefully clear explanation. A python virtual environment is an isolated environment where you use an interpreter, libraries and script that are isolated from the rest of the applications.</p><p>For those who want to go more in depth, you can check this <a href="https://towardsdatascience.com/why-you-should-use-a-virtual-environment-for-every-python-project-c17dab3b0fd0">post</a>.</p><h3><strong>Let’s get our hands dirty!!</strong></h3><p>Creating the Virtual Environment in Windows 10 is a bit different from the Linux distros.</p><p>First, I will create a Test folder where I will build my virtual environment.</p><pre>C:\Users\Amin\Desktop&gt;mkdir Test &amp;&amp; cd Test</pre><p>Now, we build the virtual environment.</p><pre>C:\Users\Amin\Desktop\Test&gt;python -m venv .env</pre><p>If you enter the .env file you should see something like that.</p><pre>C:\Users\Amin\Desktop\Test&gt;cd .env<br>Directorio de C:\Users\Amin\Desktop\Test\.env</pre><pre>25/06/2021  22:12    &lt;DIR&gt;          .<br>25/06/2021  22:12    &lt;DIR&gt;          ..<br>25/06/2021  22:12    &lt;DIR&gt;          Include<br>25/06/2021  22:12    &lt;DIR&gt;          Lib<br>25/06/2021  22:12                95 pyvenv.cfg<br>25/06/2021  22:13    &lt;DIR&gt;          Scripts<br>               1 archivos             95 bytes<br>               5 dirs  722.514.280.448 bytes libres</pre><p>Then, we have to activate the virtual environment.</p><pre>C:\Users\Amin\Desktop\Test\.env&gt; cd ..<br>C:\Users\Amin\Desktop\Test&gt; .env\Scripts\activate.bat</pre><p>Once, the virtual environment is activated, all the packages we install will be installed inside the virtual environment.</p><p>And here, is where things started to get messy.</p><p>When I tried to pip install pandas, I got the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*G_a-qgewuY8yrws-kQwl7w.png" /><figcaption>Screenshot made by myself</figcaption></figure><p>Navigating through Google I found these two solutions:</p><ol><li>Adding the following environment paths:</li></ol><pre>D:\Anaconda3 <br>D:\Anaconda3\Scripts<br>D:\Anaconda3\Library\bin</pre><p>If you don’t know how to add an environment path, check that <a href="https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/">post</a>.</p><p>2. Update pip.</p><pre>python -m pip install --upgrade pip</pre><p>First, I added the environment path, and it didn’t work. Then I tried updating the pip packages from Windows cmd, and it didn’t work neither.</p><p>Then experimenting a bit I found the solution to my problems, I updated the pip packages from the Anaconda Prompt:</p><pre>C:\Users\Amin\Desktop\Test&gt;.env\Scripts\activate.bat<br>(.env)C:\Users\Amin\Desktop\Test&gt;cd .env<br>(.env)C:\Users\Amin\Desktop\Test\.env&gt;cd Scripts<br>(.env)C:\Users\Amin\Desktop\Test\.env\Scripts&gt;python.exe -m pip install --upgrade pip</pre><p>It fixed my error and after that I could install pandas.</p><p>Having built the virtual environment and installed all the packages I needed, it was time to code. I like to open VSCode from the terminal, that way it opens on the folder you are working on.</p><pre>(.env) C:\Users\Amin\Desktop\Test&gt;code .<br></pre><p>Now, you can create your python file on the project folder.</p><p>Sometimes VSCode will use a python interpreter different from the one saved in the virtual environment. To get the right interpreter, press Ctrl+Shift+p and the Command Pallert will open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*xOgzSWwYpeGvxcOZHU24zA.png" /><figcaption>Screenshot made by myself</figcaption></figure><p>Then click on <em>“Python: Select Interpreter”</em>, and it will show a list of interpreters. You have to look for the one that has the route in the virtual environment folder, in our case .env.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*_Saq8VIXFXkXpigOGSC-qg.png" /><figcaption>Screenshot made by myself</figcaption></figure><p>If you can’t find it (like me) or you want to use a virtual environment located in another folder, you will have to add the python interpreter path manually.</p><p>Press Ctrl+Shift+p, and then type <em>‘Workspace’ </em>on the search bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*cnPAPhd5JOezsiUIs69Dpg.png" /><figcaption>Screenshot made by myself</figcaption></figure><p>Click on <em>“Open Workspace Settings (JSON)”</em>. It will open a JSON file, then write the following:</p><pre>&quot;python.defaultInterpreterPath&quot;: &quot;.env/Scripts/python.exe&quot;</pre><p>Edit: it used to be <em>“python.pythonPath”,</em> but now is subtituted by <em>“python.defaultInterpreterPath”</em>:</p><p>In <strong><em>virtual_environment_name </em></strong>put the name you assigned to your virtual environment.</p><p>Now, you are ready to build your application on a virtual environment.</p><h3><strong>Make it reproducible</strong></h3><p>When you have built your application, you can use the following command to get a requirement.txt file.</p><pre>(.env) C:\Users\Amin\Desktop\Test&gt;pip freeze &gt; requirements.txt</pre><p>It will save all your project dependencies, so the next time you need to recreate your environment you just have to run the following command.</p><pre>pip install -r requirements.txt</pre><p>And it will install all your project needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdd99fdf4d66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/troubleshooting-virtual-environment-setup-with-windows-10-and-vscode-fdd99fdf4d66">Troubleshooting virtual environment setup with Windows 10 and VSCode</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>