The server that I am using has an older version of python installed, and I am unable to install packages. Is there a workaround to importing python modules? If I can create my own module and append the directory to be able to import the newly created module, then I am assuming that I should be able to do the same for already built packages. I just need to know how I would be able to install what is required for numpy and then import it using a similar method as when creating modules.
I would recommend that you find a machine to install the same version of Python to match your server. Perform the pip install from that stand alone machine. Do some level of testing to make sure that the code with run with that version of Python and everything is happy. Just the other day I found out the hard way that TensorFlow would now work on the latest Python.
The libraries are being installed for me under c:\users\<profilename>\AppData\Local\Programs\Python\Python36\Lib\site-packages So you could then copy that over to the server.
I found this link that is saying the same thing.
https://superuser.com/questions/943980/is-it-possible-to-install-python-packages-without-a-direct-outbound-network-conn
Good Luck with it.
Related
I am learning Python specifically for data science and have little programming language although I'm a bit more familiar with R.
I installed some modules e.g. pandas and matplotlib, using the code:
python -m pip install [name_of_package]
which appear to be successfully installed, however, the console cannot find the packages when I type: import pandas
What I discovered was that the packages and Python have different paths.
For Python, the path is:
C:\Users\stone\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9
For the packages, the path is:
c:\users\stone\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages
I believe the different paths are responsible for Python not finding the packages.
My question, therefore, is how can I point pip to install in the Python path? In other words for the import to be successful.
This entry seems to be similar to my question but the answers are confusing and may have been become out of date. If answering, please be explicit with the code. I'm very new to this.
Note: I really don't want to install it in a virtual environment because it is needed presently.
Thank you in advance.
Python is probably not finding your pandas library, because it's installed in a folder where python is not looking into by default.
When you type "import pandas" python is going to look for a package named pandas within a list of folders set by default.
To solve your issue you can move/reinstall pandas into a folder which python searches through by default or you can add another folder to search through.
Here's a way to do it with python adding directory to sys.path /PYTHONPATH
I am the original poser of the question and found a simple solution that worked for me based on the recommendation of python.org.
First, I uninstalled all python programme from my system
During the reinstall, I checked the box to allow adjust the system PATH environment variable
After installing, I used the `python -m pip install
[name_of_package] to install the pandas packages.
These solved the problem and I am now able to import packages without an error message.
The current path to packages is now:
c:\users\stone\appdata\roaming\python\python39\site-packages
Why we have to install the python packages before using them?
I am currently working on a small python mysql program. What i tried to download the python connector module from mysql webpage and simply unzip it and place it in the same folder of my code.
And I can import the module properly.
So what is the meaning of installing those packages? Can I use those packages like matplotlib, numpy without installing them ?
Is it possible to have all the required packages installed on a folder so that i can move it to another computer and run my program with only CPython installed (I don't want to install any package on this computer)?
it's not that simple :-)
some packages have dependencies, you also need to download and extract their dependencies (you need pacakge x,and package x uses y) pakcage manager handles that
some package have some c code (they need to be compiled before use (ujson or postgres module) package manager handles that
when your share your code instead of sharing dependencies you simply add a file containing the list of dependencies (requirements.txt) and other user can simply install all dependencies using package manager
Installing a python package enables us to use it anywhere on our system. If we just place the package in the same directory as our script then it may well work, but only for scripts in that directory.
Some packages also rely on others to function properly, and the installation of a package may well install those pre-requisite packages for you. You may be able to do this manually, but you'd have to put them all in the same directory as your script every time you wanted to run it.
So installing the packages is the easiest way to use them.
You don't have to install them, and in some cases you wouldn't install them on your system; if you had split your code across two files and imported one file at the top of the other for example.
In fact, you don't really need install package on your system.
But if you install it, you can use these packages every where on your system.
Also, you can create a requirement.txt file to enable install all packages that you need on other computer. You can check this manual https://pip.pypa.io/en/stable/user_guide/#requirements-files
I am trying to run a program I forked off of Github (I will link it if needed to solve this problem)
Basically, the program just has one python file, which I should be able to run. In order to run, there were some other libraries I needed, such as SciKit-Learn. MOst of these seem to be fine, but one of them (Panda 0.8.1) doesn't seem to work. I installed panda just like all the other libraries, and did it a few more times to make sure.
When I try to run the python file, this is the error code I get:
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 15, in <module>
raise ImportError('C extensions not built: if you installed already '
ImportError: C extensions not built: if you installed already verify that you ar
e not importing from the source directory
How do I avoid whatever it is that I'm doing wrong?
Thanks!
Presumably you installed pandas from source. Your problem is that the pandas library - like quite a few others - includes C extensions, on Linux installing from source, i.e. downloading .zip or .tar.gz files, unpacking them and running python setup.py install is all you need to do to get the .c source compiled because everybody already has the necessary tools. On windows you either need to build the C code informing the system that you do have appropriate tools, (after you have got them), or get the built tools from somewhere else.
If you uninstall pandas and go here then locate the pre-built pandas that matches your operating system, python version, etc., download it an run it then your problem should go away.
In general there are two ways of avoiding ever getting this sort of problem:
Look to see if there is a windows installer for the package you are downloading or
Use a sensible OS like Linux
Yeah, building from the source sometimes can be troublesome. Just use a binary version which you can download e.g. from the pandas website:
http://pandas.pydata.org/getpandas.html
Another great possibility is to use a package manager like pip. A one liner in the terminal saves the day (http://www.pip-installer.org/en/latest/installing.html):
pip install pandas
Maybe you already changed to Linux - if so, the simplest way is like for Ubuntu:
sudo apt-get install python-pip
sudo pip install pandas
I'm in the process of trying to install rpy or rpy2 on my Macbook so I can use R from python. Information about rpy can be found here: http://rpy.sourceforge.net/index.html
My problem is in the installation itself. I can't seem to make python recognize Rpy using import command: I keep getting the message "No module named rpy2". Does anyone know where I can find some step-by-step instructions on how to successfully install this? I have already installed both python and R, and both are working perfectly. Thanks in advance!
Try easy_install rpy2. You need to install easy_install before that.
I took that from here
I long gave up on these issues on my Mac. Since I installed OS Lion, I found that I needed to switch to MacPorts and then installing packages like RPy2 from their repository.
I know some people like to dig into the system and learn all the idiosyncrasies of the architecture and keep a vanilla install of python on their Mac. I find that i get problems like yours too frequently and they distract me from real work.
I just download the MacPorts modules when I need them and get on with the problem at hand. Others say the same thing about HomeBrew but I have only worked with MacPorts and it makes installation of modules too easy. You may want to invest some time investigating if either of these solutions work for you.
Another approach to using package managers like MacPorts or HomeBrew is to use a virtualenv and install python and all related modules there. Again, not a solution I have tried directly, but a quick search will show you many endorsements for this approach to using a specific Python executable and packaging its modules In an isolated environment.
as long as you have pip installed on your mac, then life will be easy as:
sudo pip install rpy2
If you want rpy it isn't on macport, at least a search of their packages only showed rpy2. According to the rpy web site its in fink. However at the moment fink is down so I can't verify this. Which is irritating because I need rpy (not rpy2) because another package has a dependency on it.
I also tried pip to find rpy and it said no package, which is a shame because pip is great for python installs (provided I remember to use 'sudo' first.
I use Kodingen.com to test python scripts. I would like to install new python packages on Kodingen. I know I can use the 1-Click installation of the App-Store to install new packages from ohloh.net. When I install a package, it create a new directory in httpdocs folder. And then? How to setup the python package to use import in my scripts? Is it possible for a user to do it?
I'm looking for the complete procedure. As example, we can use PIL (Python Imaging Library). How to install it?
For information, Kodingen use a linux server.
I asked a similar question but this one is a more general question about the python packages install.
hey thammas, we are working on kodingen v1.0 with which you will be able to use your own server connected to your account. then you can install anything and use it freely.
but now, kodingen provides shared hosting account that doesn't enable anyone to install anything. same applies to ruby gems. but we will make this possible very soon.
just to reiterate, kodingen is able to run python/perl/php scripts, just not external/custom libraries until we give you your own servers. hope it clarifies.