How do I download a package on a USB device? - python

So I am just beginning to learn Python and I was wondering whether it is possible to install a package onto a USB drive instead of onto the device itself. I wanted to download a package but I didn't have enough storage to install it. So I put the project into a USB drive and opened the project and tried to download the package hoping it would use the storage in the USB, which it didn't. Is there a way to do this or do packages need to take up the storage of the device instead? For context, I am using PyCharm.
I tried to look for advice on youtube and here, but I can't seem to find any, or I just do not know what to look for. Any help would be appreciated, thanks!

Packages are installed in the base environment of Python itself, not in your project.
I think you can achieve your goal by creating a new virtual environment on your USB drive. Then install all the required packages into that virtual environment and run your code.
In the bottom right of PyCharm you probably see "Python 3.x ...". Click on that, then "New Interpreter" > "Add Local Interpreter". This brings up the environment menu, in which you can indicate where a new environment should be created, and with which manager. I prefer Conda, but Virtualenv should work fine for you. Once that is set up you can install the packages from PyCharm as long as this new environment is activated (indicated in the bottom right of the main screen).

Related

How to run python from usb?

I am trying to download and run Python and PyCharm off of a usb stick because I am a newbie and suck with remembering all the OS specific setup, so the code I work on at work, does not work on my home computer.
When I try to run python.exe from the usb drive, I get the error "Windows cannot access the specified device path or file you may not have appropriate permissions". I am local admin and can open folders, just not run the exe.
Any help would be greatly appreciated
TL;DR I want a centralized place for all of my code to be neatly and easily stored, retrieved, edited, and tested.
use python virtualenv
pip install virtualenv
python -m virtualenv mypython
It will generate a 'new' python (mypython) that you may copy into your USB stick.
Read the documentation here.
Try Portable Python.
Python virtualenv use your installed python that's why you can't share it using usb stick or add it on your github repository.

Do I need to have Python installed on my machine to run a code in a virtual environment?

I want to create a python virtual environment in a Windows network folder, and then activate and use this venv on another computer. My question is, do I need to have python installed on all these machines that i want to use this virtual environment?
If so, why do I need to install python everywhere if it's already inside this venv i will create, along with all the necessary packages?
Virtual environments are not designed to be portable. For instance, if you have entry points installed then moving them to another machine would break their shebang lines. And even if you do it on your local machine there's no guarantee something else wasn't structured to be directory-specific such as your username! Take in consideration that when creating Python venv, it will be pointed to your python path where your username is part of the path, so its not a good idea. Although why not upload py files to the cloud, share via Bluetooth to phone or copy-paste to a usb stick.

Cannot Create an Interpreter in PyCharm

I downloaded Python 3.8.
I downloaded PyCharm Community Edition 2019.3.4. Saved it in new folder in the Desktop directory.
In PyCharm, when I click on File > New Project, I...
1.) Have the location set to C:\Users\User\Desktop\newProject
2.) Have New environment using set to Virtualenv
3.) Have Base interpreter set to C:\ProgramFiles\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64_qbz5n2kfra8p0\python.exe
I have a Windows 10 Home computer
When I click on the Create button, I get the attached error.
What can I do?
The error says it has access problem while accessing python.exe. Files inside WindowsApps are for systems use and cannot be accessed manually by users due to access permission.
Also you installation does not seem right as python.exe is present inside WindowsApps.
Please follow the simple installation guide for python. You might run into many other problems later.
I would suggest reinstalling python. It should go directly into C:/ drive or C:/ProgramFiles.

Is there anyway to save Google colab environment to somewhere and reuse it?

I've tried virtualenv and conda, it was successfully installed but I cannot active the virtual environment. Then I think about saving Colab environment (I mean installed libraries) to somewhere, maybe Google Drive then I can reuse it.
Is it possible?
For the questioner and for whom reached here because of the same issue,
A good answer was posted after this question :
How do I install a library permanently in Colab?
It uses the way you install libraries into your Google Drive.
You can add a directory in GDrive to PYTHONPATH, e.g. /content/drive/My Drive/Colab Notebooks/
Then Python will search for an installed library there. You still need to mount to GDrive every time, though.
It should be covered in the documentation for virtualenv https://virtualenv.pypa.io/en/stable/
Once you have created a virtual environment with:
virtualenv NAME
That creates a new directiory named NAME for your virtual environment.
Then you can activate it with:
source /path/to/ENV/bin/activate
or
. /path/to/ENV/bin/activate
(note above, "[DOT][SPACE]/path/to/ENV/bin/activate")
That directory should be fine to move around as you please, thumb drive, dropbox, etc. If the systems you intend to use your enviroment on differ too much there could maybe be some issues.
However, I prefer to use pyenv + pipenv for all my virtual environment needs.
If you have the time I strongly recommend learning about them, it is worth it.
Pipenv https://github.com/pypa/pipenv is a great manager for python virtual environments.
Pyenv https://github.com/pyenv/pyenv is for installing and managing different versions of python so you might not need it.
This way your virtual environment is more robost and easier to get up and running if you move it around or share it with others.

Setting up virtual environment in PyCharm

Greetings to everyone!
I've got a little issue in a project made by someone in PyCharm, with virtual environment(VE) precisely. I've set this VE up few months ago and didn't use it for some time. Now i need to go back to it, because it has a lot of necessary things installed. Therefore there is one more battery needed to be installed into this VE - it is soundcloud API. I installed by directly from PyCharm in project settings, i checked whether this VE is still a default VE - it is. But project keeps complaining that there is "No module named soundcloud".
Can you show me the way i can fix this?
Thanks in advance.
In settings, under the Project section (in the left pane) go to Interpreters. From there you can select a found environment or click the + to add your own from a path. Find the environment you created and add it to the list. Then, once you select the environment you can see the installed modules underneath. You can add new modules through their built in pip.
After that, it'll take you to the first page where you have to select your custom environment from a drop down.
Good luck!
Edit: Reread your question. Sometimes when I can't get the module to be recognized in PyCharm, I do a pip install through the command line in the virtual environment. Then restart PyCharm.
Navigate to the environment in cmd and run python -m pip install -U SOUNDCLOUD_MODULE and it'll work.

Categories