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.
Related
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).
I have a Ubuntu server with restricted access. There I will be hosting my application.
I trying to run Python scripts which were working with the default packages provided by the server. I want to work with numpy and other modules.
As I cannot install or download or do anything, I created a python server in my local machine (WINDOWS) using WSL to emulate the Linux file system and copied the python environment files to the application directory and deployed in cloud.
The problem is no matter in whatever way I try I cannot import numpy (or any module which I copied). I moved all the site-packages to the location of my Python script (As the current script's path will be there in the system path) and tried to import but no luck.
Please help me with crack this in any possible or impossible way.
I am trying to achieve this for the past 6 days and cannot do it.
Please, I have to achieve this at any cost. I have attached my latest structure.
Thank you in advance.
My Folder structure screenshot:
EDIT:
Ok. Let me get this straight. I have a Linux server (Ubuntu 18.04) where I am hosting an application. From that application, I am calling python scripts for some machine learning purposes. It is restricted server and I cannot access it. The only way that I found out the Linux distro version is through Java code by calling some terminal commands using "ProcessBuilder". As the server is highly restricted I cannot run any of the Linux commands like echo, set, export, sudo, wget/curl,...etc., Since, python3 is already provided by Linux (by default) I am using that python3 command to call my python scripts (from Java code using "ProcessBuilder") and execute them.
If it is a normal script (if I am using python standard libraries) it is working fine. In one of the scripts I am using "numpy". So, I want to import that module. I am doing the development in a windows environment. So, to emulate the Linux file system for importing packages I created a virtual environment in WSL with same Ubuntu version and installed numpy and then replaced all the symlinks inside those packages with the required files. Then I copied the entire environment and pasted in my resources directory (which is in windows environment) and deployed. No luck.
So, I made a zip file for only "site-packages" folder inside that environment. Then I copied the zip file and pasted in my resources folder and deployed. No luck. The error that I always see is "numpy.core._multiarray_umath". All the articles and in GitHub also tell us to re-install the package. But, I cannot install. I don't have any such access.
How can I import numpy without installation? If there is any work around to achieve this please explain, I will do it. Even if it is harder, complex and time-consuming I am okay with it. I want to achieve this.
Let me preface this with:
a warning to please check the AUP (acceptable use policy) of the server you are using, and/or contact the server administrator to make sure you are not violating any rules.
I can think of quite a few reasons why this won't work. If it doesn't, then there may still be workarounds, but they'll be technically complex.
So if I'm understanding you correctly:
You have very limited access to the server; basically only the ability to upload (apparently) and run Java code.
You've also been able to upload Python code and run it through your Java code through ProcessBuild.
You do not have access to log in to a shell, execute arbitrary command other than through ProcessBuild, etc.
Of course, you do not have the ability to install site-packages into the system Python environment.
So ultimately, what you'll probably need to do is something like:
Create a Python3 virtual environment (which doesn't seem to be what you are actually doing) on WSL. By a "Python3 virtual environment", I mean venv, which allows you to create a user-level (not system-level) directory with your packages.
So something like (from inside your project directory):
python3 -v venv venv
source ./venv/bin/activate
Your path will be adjusted so that your python3 and pip3 commands will be found in the venv path. pip3 install numpy will install it into this virtual environment (not the global/system Python).
Upload that entire venv directory to the server. You seem to have some way of doing this already.
You're going to have to have some way of running the Bash shell through ProcessBuilder. Since you have the ability to run python3 through ProcessBuilder, I'm kind of assuming that you will be able to do this as well.
You'll need to (through ProcessBuild) activate the virtual environment on the server, <path_to_project>/venv/bin/activate and, in the same Bash shell run your code.
This will look something like:
bash -c "source ./venv/bin/activate; python3 main.py"
I have recently started learning python using code academy and today I downloaded everything that I thought I would use. I downloaded Python and Atom. I have two separate drives on my computer. An SSD with not much storage and a hard drive with a lot of storage. My Windows is installed on the SSD, but I wanted to download python and atom on the hard drive, so I did so. When I installed Python I made sure to check add to PATH and the environmental variable thing. Now when I go to the command prompt, it shows "C:\Users\Gustavo>" but my python is installed on a different drive. Is there a way I could make this work? Thanks a lot.
There are two ways to install python:
Download directly from the website
Use a package manager
Case 1: Download directly from the website
Go to the python's website to download the version you would like to use.
Install the downloaded file (During the installation you can customize the installation directory)
Make sure to enable "Add python.exe to Path"
After installation has been completed, open your command prompt and type where python. Your python directory should be printed.
If all is good, then typing python should launch python in your command prompt. You can also run python by cd in the directory where your python is located and launch the .exe
You have mentioned about changing path and environmental variables, and that's probably for the purpose of keeping multiple versions of python. If that's the case, there's actually a quick fix for this:
Go to the folder where you installed Python.
Copy the python.exe file, and rename that copy in the same directory as python3.exe (If you installed version 2, then rename as python2.exe).
Now in command prompt type python2 or python3 and you should be able to launch either versions respectively.
Note: If you face issues regarding paths, then you should detail the error messages.
Case 2: Use a package manager
Choose a package manger: chocolatey, scoop, and others.
Check out these links for changing package manager's installation directory, installation method varies by the managers, so you should consult the developers should you experience problems:
chocolatey
scoop
Package managers will manage the versions for you, if you choose to install multiple versions. You should refer to the package manager's website for detailed information. However, you can quickly check the installed version by typing python --version. The python version number should be printed back to you, same applies to python3.
Double check your installation directory by which python
Type python or python3 to run your python of choice.
Lastly, you have mentioned atom. Atom is just a text editor: you can write python codes with it.
When you are done editing, you can open the command prompt and navigate to where your code resides, and type
python filename.py
This will run your code directly from the command prompt. There are many atom plugins available to make this process seamlessly integrated within atom. iPython and Jupyter plugins are first things that comes to my mind, you should specifically check out Hydrogen.
I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).
I have a problem with the following command:
setup.py install.
I know it should work, I have tried it on a laptop but I don't have access to it at the moment. I need to complete a homework so I tried the same on my PC. And when I type the same command into cmd it just runs pyscripter as if I would use right click on setup.py and click edit with pyscripter. It does nothing else. I am sure that I am in the right folder in cmd.
My python version is 2.7 and my pyscripter version is v2.5.3. My OS is win7. I have tried to install other modules but I get the same response.
Has anyone encountered the same problem? I have searched the internet but I haven't found any answers to this problem.
Assuming that you installed Python 2.7 in the default folder i.e. c:\python27, then you can type:
c:\python27\python setup.py install
Wherever you installed it, you should append that path to your PATH variable (you'll need to log on as an admin to do that).
Do python setup.py install instead.
Windows is probably not set up to recognize .py files as executable.
Recently our class at school used all of the above programs. about a handful of students had trouble installing like you described. Fortunally I didnt not have this problen but I can suggest you use Administration priviledges.
Make sure you download the correct version.
Go to your download folder and look at the file you have downloaded (do this via my computer not from your web browser)
Right click on the file and then click run as an administrator
Here is an awesome site for windows binaries: http://www.lfd.uci.edu/~gohlke/pythonlibs/
If the library you need is there, just download and install like any other windows program...