Installing Jupyter in PyCharm Professional problem - python

I am using PyCharm Professional to install Jupyter and following the tutorial: https://www.jetbrains.com/help/pycharm/jupyter-notebook-support.html
However, after creating the .ipynb file and trying to run it I run into the following error: "This file does not belong to the project". Also I have "Jupyter file outside of the module" greyed out (see screenshot). Is there anything I am missing? I've created a new .ipynb file inside the project (see screenshot).

The problem here is that your .ipynb folder is inside the venv folder. This venv folder should only contain the Python interpreter and third party packages. You should not place any files you create under venv. Instead, put them directly in the module folder jupyter-eda.

I noticed the scratches folder was not in the project, so it helped to just add it...

Related

Jupyter in VSCode

enter image description here
At first, jupyter notebook works fine. BUT, whenever I try to use the other ipynb file, jupyter notebook does not work and send this message. How should I deal with this?
Have you checked which python interpreter you are using in the Jupyter Notebook?
With the different names of the .ipynb file, it will take the different kernels, and it is stored in the database.
First of all, create a virtualenv. Open the terminal using Ctrl+Shift+`.
In the console, type python3 -m venv venv.
This will create a folder named venv in your working directory.
Now, in the bottom left corner, you will find the selected python interpreter. Click that and change it to venv.
(If windows raises permission error, In your vsCode settings, add the following lines.)
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
Now delete all previous terminals and open a new terminal.
Install the required packages using pip and carry on.

PyCharm error: Cannot run program, error=2, No such file or directory

I am getting the following error message when attempting to execute Python code in PyCharm:
Cannot run program "/Users/x/.virtualenvs/untitled/bin/python" (in directory "/Users/x/PycharmProjects/untitled"): error=2, No such file or directory
I made sure everything was updated and restarted my computer, but I still get the same error. I have no idea what the problem is.
Edit
I just opened my terminal and was faced with this error message:
virtualenvwrapper_run_hook:12: no such file or directory: /usr/local/bin/python3.7 virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.7 and that PATH is set properly.
I have no idea what happened here. I certainly didn't touch any of this.
Edit 2
If I execute Python3 --version, I get Python 3.8.5.
Edit 3
I followed this, but this error remains:
Edit 4
This is the current state:
I think this is related.
If it helps at all this is what my venv settings looks like.
I don't have the answer as to why it happens, but I find its usually when renaming the project.
In the past i've recreated the project and copied the project files directly from the old folder to the new one in a file explorer (not pycharm) and its fixed it.
This Error Occurs because when you rename the file you need to update the file path name also...
.......Solution...........
click on Edit Configurations (near the green 'run' play button)
Where it says 'Script Path' at the end of the string is where you find the name of
your file
Change the name to the updated file name
Probably the root library has been deleted or corrupted.
I suggest to delete the venv library in explorer and then write the following commands in the terminal
> C:\Users\MY\PycharmProjects\pythonProject>py -m venv venv
> C:\Users\MY\PycharmProjects\pythonProject>cd venv\Scripts
> C:\Users\MY\PycharmProjects\pythonProject\venv\Scripts>activate
For me, it was the symbolic link in the project. Running this command fixed it:
xcode-select --install
You may want to check the contents of the 'activate' script inside your venv. It contains a few hardcoded, absolute paths to files and directories within your environment. If you change something in that environment, e.g. move a file or directory around, these paths can easily become invalid.
Similar issues can arise when you, for example, create a virtual environment inside a virtual machine, then open files in PyCharm from outside that machine.
For me, the problem was that I created the virtual environment through the PyCharm settings and ticked "Inherit global site-packages", I think. Once I removed the virtual environment and created it using the old fashioned way, i.e.
mkvirtualenv projectname --python=python3.10
everything fell into place.

Where is the python workspace path located in PyCharm?

I created a Python project using PyCharm (2019.3.3) in folder F:\FolderA then I realized I meant to create it in F:\FolderB. So I copied my project from FolderA to FolderB. Now when I try to install a package, PyCharm says:
Cannot start process, the working directory 'F:\Projects\FolderA\MyProject\venv\Scripts' does not exist
I come from C# background, and everything project related is saved in .csproj file. Does Python have a similar file where it writes project/workspace information? So I can point to the correct path?
Inside /venv/scripts folder there are three "Activate" files. It holds the path to the old directory.
Replace the old paths with new paths
Restart PyCharm
Install package
Here's a screenshot of the path to the files:

How to get terminal to default open into my virtual environment?

I've created a virtual environment for Python and VSCode, but everytime I open up the terminal, rather than opening up to the work environment folder, it opens up to the folder where I keep my .py file.
Let me explain my steps.
I've created a Work folder, then a work environment folder inside of it. C:\Work and C:\Work\work_env
Next I've created a folder in C:\Work\myprojects to place my .py files in.
Now when I open up the terminal in VSCode, it runs the Activate.ps1 file and my work environment is ready to use but ONLY when I navigate into my work environment folder using cd in the terminal.
Is there a way to default it so that the terminal is open to the work environment right away? I followed all the steps in this short tutorial and this guy got his terminal to work that way but it's different for me. https://www.youtube.com/watch?v=Wuuiga0wKdQ
Thanks!
Add the following line to your settings.json:
"terminal.integrated.cwd": "DESIRED/PATH"
You can find more details here.

Jupyter file path change to project location

I have experience in RStudio and Visual Studio and new to Python environment, I am struggling to set Python project in Jupyter like above two IDE. Here when I open new notebook then it create it as default location and I am not finding a way to put the file in my project location, Just want to know how to make production ready project like folder structure in Jupyter.
If this post is duplicate then I am not able to search the original one.
Under Linux, specify which directory Jupyter notebook uses to locate the notebooks with the command:
jupyter notebook --notebook-dir=<path to notebook location>
I have this aliased in my .bashrc file to jupytern.
In Windows I created a desktop shortcut and specified the notebook directory as:
C:\python36\Scripts\jupyter-notebook.exe --notebook-dir=<path to notebook locations>
You need to change the path to the jupyter-notebook.exe file to where it is on your installation.

Categories

Resources